|
Posted by peter on 06/23/07 11:32
> two array
> A) 1, 2, 3, 4, 5, 6
> B) 4, 6, 9
>
> how can to have an array
> C) 4, 6
> all the B's values that have value in A
>
> and
> an array
> D) 1, 2, 3, 4, 5, 6, 9
> a simple union of A + B with no duplicates values
not necessarily the best solution but something like the following works:-
<?php
$a = array(1,2,3,4,5,6);
$b = array(4,6,9);
$c = array();
$d = $a;
foreach ($b as $value)
{
if (in_array($value, $a))
{
$c[] = $value;
}
else
{
$d[] = $value;
}
}
print_r($c);
print_r($d);
?>
this of course assumes that there will be no duplicate entries in $a already
Navigation:
[Reply to this message]
|