...

View Full Version : Comparing 2 Arrays



daemonkin
08-07-2007, 11:07 AM
Looking for a function if one exists that can compare 2 arrays and tell me the elements that are the same in each.

My array example is:

Array
(
[0] => Array
(
[word] => the
[nav] => Array
(
[0] => 1
[1] => 3
[2] => 7
)

[sub] => Array
(
[0] => 1
[1] => 2
)

)

[1] => Array
(
[word] => char
[nav] => Array
(
[0] => 1
[1] => 3
)

)

[nav] => Array
(
[0] => 1
[1] => 3
[2] => 7
)

)



I am looking for similar numbers in the sub array ['nav'] and in the case above the results should be 1 and 3.

Can anyone help?

D.

anarchy3200
08-07-2007, 12:37 PM
Try having a look at:
array-intersect (http://www.php.net/manual/en/function.array-intersect.php)

daemonkin
08-07-2007, 04:08 PM
Thanks I will do.

D.

daemonkin
08-13-2007, 05:28 PM
Another problem has occurred.

I now have the following array:

Array
(
[0] => 0
[1] => 1
[2] => 2
)

where the values are indexes in another array.
Since there are 3 values I was planning on adding these to the array_intersect function but I want to add them dynamically to the following:


$aTmp = array_intersect([array key values in here]);

Is this possible?

Thanks for any help.
D.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum