note 85006 added to function.array-intersect
| From: | Esfandiar--e dot bandariatgmaildotcom at osu1 dot php dot net | Date: | Sun, 10 Aug 2008 07:44:48 +0000 |
| Subject: | note 85006 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143342@lists.php.net to get a copy of this message | ||
Regarding array union: Here is a faster version array_union($a, $b)
But it is not needed! See below.
<?php
// $a = 1 2 3 4
$union = // $b = 2 4 5 6
array_merge(
$a,
array_diff($b, $a) // 5 6
); // $u = 1 2 3 4 5 6
?>
You get the same result with $a + $b.
N.B. for associative array the results of $a+$b and $b+$a are different, I think array_diff_key is
used.
Cheers, E
----
Server IP: 64.71.164.2
Probable Submitter: 76.200.152.121
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/85006
Del: integrated -- https://master.php.net/note/delete/85006/integrated
Del: useless -- https://master.php.net/note/delete/85006/useless
Del: bad code -- https://master.php.net/note/delete/85006/bad+code
Del: spam -- https://master.php.net/note/delete/85006/spam
Del: non-english -- https://master.php.net/note/delete/85006/non-english
Del: in docs -- https://master.php.net/note/delete/85006/in+docs
Del: other reasons-- https://master.php.net/note/delete/85006
Reject -- https://master.php.net/note/reject/85006
Search -- https://master.php.net/manage/user-notes.php