Forum Moderators: coopster
$array1 = array("a", "b", "c", "d");
$array2 = array("a", "c", "e", "h", "u");
What I need is array of all values, but withour any doubles:
output = a, b, c, d, e, h, u
However if I use
$array1 + $array2 = a, b, c, d, u //no e and h
And
$array2 + $array1 = a, c, e, h, u//no b and d
I see that + appends not different values, but different keys. Array_merge would do if not for the double values.
Best regards
Michal Cibor
I did it however with foreach loop (I don't know which is faster, but it doesn't really matter to me for now). This is the code:
function merge($a, $b){
$c = $a;
foreach($b as $value){
if(!in_array($value, $a)) $c[] = $value
}
return $c;
}
It handles non arrays badly however as I checked.
Best regards all!
Michal Cibor
$array = array_unique [php.net](array_merge [php.net]($array1, $array2));