Connecting Tech Pros Worldwide Forums | Help | Site Map

combine two arrays ldap_search results to give one array with uniquevalues?

macca
Guest
 
Posts: n/a
#1: Nov 3 '08
Hi,

I'm doing an two ldap_search queries and I need to combine the two
results into one single array containing all the results from each but
removing duplicates.

I have tried built in php functions such as array_merge (which gives
me duplicates) and array_unique which does not work either.


Any ideas?

Thanks.

Curtis
Guest
 
Posts: n/a
#2: Nov 3 '08

re: combine two arrays ldap_search results to give one array with uniquevalues?


On Sun, 2 Nov 2008 17:01:07 -0800 (PST), ptmcnally@googlemail.com
wrote:
Quote:
Hi,
>
I'm doing an two ldap_search queries and I need to combine the two
results into one single array containing all the results from each but
removing duplicates.
>
I have tried built in php functions such as array_merge (which gives
me duplicates) and array_unique which does not work either.
>
>
Any ideas?
>
Thanks.
>
Yes, you can use array_diff(), which will look at the arrays' valus.
Note that the key associativity of the first array is maintained in
the return array.

<URL:http://php.net/array_diff>
--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
macca
Guest
 
Posts: n/a
#3: Nov 3 '08

re: combine two arrays ldap_search results to give one array with uniquevalues?


That wont work. I need all the unique values from both arrays in one
array, not just the difference. but thanks...
Guido Bernaerts
Guest
 
Posts: n/a
#4: Nov 3 '08

re: combine two arrays ldap_search results to give one array with uniquevalues?


Am Mon, 03 Nov 2008 04:19:02 -0800 schrieb macca:
Quote:
That wont work. I need all the unique values from both arrays in one
array, not just the difference. but thanks...
have not done much php lately but does a combination of merge and unique
not work? something like this:

$arrRes= array_unique(array_merge($arr1,$arr2));

hope its not a stupid sugestion ... first try of use net by my side ...

cu
macca
Guest
 
Posts: n/a
#5: Nov 3 '08

re: combine two arrays ldap_search results to give one array with uniquevalues?


yes i have tried this to no avail but thanks for the suggestion
Curtis
Guest
 
Posts: n/a
#6: Nov 4 '08

re: combine two arrays ldap_search results to give one array with uniquevalues?


On Mon, 3 Nov 2008 04:19:02 -0800 (PST), ptmcnally@googlemail.com
wrote:
Quote:
That wont work. I need all the unique values from both arrays in one
array, not just the difference. but thanks...
Again, just looking at values, perhaps this will do it:

$a = array(...);
$b = array(...);
$c = array_merge(array_diff($a,$b), array_diff($b,$a));

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Closed Thread