stormist
asked on
PHP- I need to compare two arrays and find the values that match between them
Say i have 2 arrays
array 1 = 0-45, 1-14, 2-16, 3-25, 4-99
array 2 = 0-16 1-15 2-67 3-45 4-88
Is there a simple PHP function to return which values match in another array? In this case a comparative array that returns
0-16
1-45
since both arrays have those values?
Thanks!
array 1 = 0-45, 1-14, 2-16, 3-25, 4-99
array 2 = 0-16 1-15 2-67 3-45 4-88
Is there a simple PHP function to return which values match in another array? In this case a comparative array that returns
0-16
1-45
since both arrays have those values?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all! What would be a way to use that function but reset the keys? first one 0 , 2nd one 1. etc?
Thx!
Thx!
Use: http://pl2.php.net/manual/en/function.array-values.php
on the resulted array. Resulting array would be indexed by numbers.
on the resulted array. Resulting array would be indexed by numbers.
Example 227. array_intersect() example
<?php
$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
?>
This makes $result have
<?php Array
(
[a] => green
[0] => red
) ?>