I want to get the same value from two arrays. Example:
a[] = array(a,b,c,d,e,f,g,h);
b[] = array(c,d,o,l,p,i,u,y);
I want c[]=c,d;
see http://docs.php.net/array_intersect:
array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.
$a = array('a','b','c','d','e','f','g','h');
$b = array('c','d','o','l','p','i','u','y');
$c = array_intersect($a, $b);
var_dump($c);
prints
array(2) {
[2]=>
string(1) "c"
[3]=>
string(1) "d"
}
<?php
$arr = array_intersect(array('a', 'b', 'c', 'd'),
array('c', 'd', 'e', 'f'));
print_r(array_values($arr));
Use array_intersect($a,$b)
-- Ohh many guys answered before i typed
You can use array_intersect() function.
in_array() might be what you're looking for
Use in_array() to see if the value you're looking for is in both arrays a and b and then put it in array c (following your example)
http://www.php.net/manual/en/function.in-array.php
Try $result = array_intersect($a, $b);