note 43568 added to function.array-intersect
| From: | monte at ispi dot net | Date: | Fri, 25 Jun 2004 21:39:14 +0000 |
| Subject: | note 43568 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71699@lists.php.net to get a copy of this message | ||
I couldn't find any array union functionality in PHP (extracting the common elements between
two arrays), so the best method I could think of was to intersect them from both directions:
$arr1 = array(1,2,3,4);
$arr2 = array(2,4,6,8);
$union = array_intersect($arr2, array_intersect($arr1, $arr2));
print_r($union);
output:
Array
(
[0] => 2
[1] => 4
)
This result is the union of the two arrays.
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43568
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43568&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43568&report=yes
Search -- http://master.php.net/manage/user-notes.php