Jump to content

array_diff weirdness


blinks

Recommended Posts

I'm using the following bit of code

$diff = array_diff($pids, $pidlist); 
$diff = array_values($diff); //reindex array to remove empties
//output to $discrepancy
print_r($diff);
exit;

 

Both $pids and $pidlist contain exactly the same value; so I would have expected that value not to appear in $diff - but it is. Both $pids and $pidlist contain a few thousand values, and I've only found this one example which appears in both lists as well as $diff.

 

Can anybody shed any light?

Link to comment
Share on other sites

Sorry, I didn't explain myself very clearly. I do get a lengthy output from array_diff. The issue is that there is one particular array value from among the thousands in each array (it's an integer array)  that occurs in both $pid and $pidlist, and therefore shouldn't be in $diff, but is.

Link to comment
Share on other sites

Problem solved! Although I'm still quite puzzled about one aspect of it - print_r of $pids and $pidlist was showing up the duplicated value in both arrays. The var_dump revealed it was present in one, and missing in the other. Perhaps I put the print_r in a difference location???

 

Anyway, all good now. I traced the issue back to a bug in the parent program.

 

Thanks for your help.

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.