note 82144 deleted from function.array-diff by danbrown

From: Date: Fri, 26 Jun 2009 13:57:29 +0000
Subject: note 82144 deleted from function.array-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157536@lists.php.net to get a copy of this message
Note Submitter: merlinyoda at dotproject dot net ---- 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)

« previous php.notes (#157536) next »