note 82144 added to function.array-diff
| From: | merlinyoda at dotproject dot net | Date: | Fri, 28 Mar 2008 18:29:27 +0000 |
| Subject: | note 82144 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137684@lists.php.net to get a copy of this message | ||
Quoting Hayley Watson's note sent @ 17-Oct-2007 02:55
--------------------------------------------------------------------
A wee idiom for KEEPING only those elements of an array $a that appear in an array $b (without
introducing any elements of $b that do not appear in $a).
<?php
array_diff($a, array_diff($a, $b))
?>
...
--------------------------------------------------------------------
Um... this is really unnecessary. You just have to do this:
<?php
array_intersect($a, $b)
?>
An intersection of sets A and B is logically equivalent to the difference of set A and the
difference of set A and B
Written a little more "mathematically" using "&" as the symbol for
intersection instead of the "proper" one (which looks like an upside down U ):
(A & B) == A - (A - B)
----
Server IP: 209.41.74.194
Probable Submitter: 65.117.116.130
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/82144
Del: integrated -- https://master.php.net/note/delete/82144/integrated
Del: useless -- https://master.php.net/note/delete/82144/useless
Del: bad code -- https://master.php.net/note/delete/82144/bad+code
Del: spam -- https://master.php.net/note/delete/82144/spam
Del: non-english -- https://master.php.net/note/delete/82144/non-english
Del: in docs -- https://master.php.net/note/delete/82144/in+docs
Del: other reasons-- https://master.php.net/note/delete/82144
Reject -- https://master.php.net/note/reject/82144
Search -- https://master.php.net/manage/user-notes.php