By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Nov 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sun, 2 Nov 2008 17:01:07 -0800 (PST), pt*******@googlemail.com
wrote:
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);
Nov 3 '08 #2

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

P: n/a
Am Mon, 03 Nov 2008 04:19:02 -0800 schrieb macca:
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
Nov 3 '08 #4

P: n/a
yes i have tried this to no avail but thanks for the suggestion
Nov 3 '08 #5

P: n/a
On Mon, 3 Nov 2008 04:19:02 -0800 (PST), pt*******@googlemail.com
wrote:
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);
Nov 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.