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
https://forums.phpfreaks.com/topic/190203-array_diff-weirdness/
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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.