Voting

: seven plus one?
(Example: nine)

The Note You're Voting On

Esfandiar -- e.bandari at gmail dot com
16 years ago
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

<< Back to user notes page

To Top