You are here: Re: filter on two array « PHP Language « IT news, forums, messages
Re: filter on two array

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация