Jump to content

Check array indexes


NotionCommotion

Recommended Posts

Thanks CyberRobot.

 

A requirement is has only the three indexes, and a single array_diff_key() will not work.  I could then use a second array_diff_key() or compare the count, but expect one of the other countless array functions might be more suitable.

var_dump(array_diff_key(['a'=>null,'b'=>null,'c'=>null], ['a'=>1,'b'=>0,'c'=>2]));
//array(0) { }


var_dump(array_diff_key(['a'=>null,'b'=>null], ['a'=>1,'b'=>0,'c'=>2]));
//array(0) { }


var_dump(array_diff_key(['a'=>null,'b'=>null,'c'=>null], ['a'=>1,'b'=>0]));
//array(1) { ["c"]=> NULL } 
Link to comment
Share on other sites

Where is the data coming from?

 

I receive JSON data via a socket.  Certain data is expected based on the database.  I wish to confirm that the JSON is not providing more or less data that is expected.  I can easily enough do the array_diff_key along with confirm index counts are equal solution, but just felt there was a really slick way which would be a good thing to learn.

Link to comment
Share on other sites

That is a lot more useful info than how to handle your attempt at it. Not sure if it is, but it was smelling of an XY Problem to me.

 

Are you able to provide details on the "Certain Data" and exactly what it means regarding more or less data? Any other details may also be helpful. Are you in control of the source data? If not, what are your options in retrieving it? Are we talking about a third party API? 

 

 

Edit* Is this a third thread regarding the same project as your other two threads?

 

https://forums.phpfreaks.com/topic/302727-multiple-updates/page-2

 

https://forums.phpfreaks.com/topic/302752-insert-on-duplicate-key-update-with-composite-key/

Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.