note 23243 added to function.array-diff
| From: | soroso at mackenzie dot com dot br | Date: | Fri, 12 Jul 2002 14:43:08 +0000 |
| Subject: | note 23243 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32962@lists.php.net to get a copy of this message | ||
Array_diff has a bugged behaviour with while+list+each loops, I didn't try with foreach so I
don't know really how it'd react. So as follows:
/* Two arrays do diff */
$array_one = Array(1,2,3);
$array_two = Array(1,2);
/* Bugged behaviour*/
while( list(,$value) = @each(array_diff($array_one, $array_two)) )
echo $value."\n";
/* But this while loop never ends ... If the array_diff returns just one value , why is it never
ending?*/
/* WorkAround */
$array_diffed = array_diff($array_one, $array_two);
while( list(,$value) = @each($array_diffed) )
echo $value."\n";
Soroso J Moriarty
--
http://www.php.net/manual/en/function.array-diff.php
http://master.php.net/manage/user-notes.php?action=edit+23243
http://master.php.net/manage/user-notes.php?action=delete+23243
http://master.php.net/manage/user-notes.php?action=reject+23243