note 60344 added to function.array-diff
| From: | airatmultidotfi at osu1 dot php dot net | Date: | Wed, 04 Jan 2006 11:41:34 +0000 |
| Subject: | note 60344 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101196@lists.php.net to get a copy of this message | ||
A small thing that caused me trouble today, wich I don't see listed on this page is that
array_diff keeps the placing for the uniqe values, and removes the duplicated. This gives us empty
fields in the array, wich caused me a lot of trouble. The solutions was simply to use array_merge()
around the array_diff.
For example:
$array1 = array('blue', 'red', 'green');
$array2 = array('red');
array_diff($array1, $array2);
Will give us:
------
Array
(
[0] => red
[1] =>
[2] => green
)
But if we use:
array_merge(array_diff($array1, $array2));
We will get:
------
Array
(
[0] => red
[1] => green
)
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60344
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60344&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60344&report=yes
Search -- http://master.php.net/manage/user-notes.php