我有两个数组说Array1和Array2
Array1
(
[0] => Array
(
[name] => abc
)
[1] => Array
(
[name] => xyz
)
)
Array2
(
[0] => Array
(
[name] => abc
)
[1] => Array
(
[name] => qwe
)
)
我想从两个数组中获取公共值,因此FinalArray应为:
FinalArray
(
[0] => Array
(
[name] => abc
)
)
我试过这个: in_array函数 但它只返回一个空白数组。
答案 0 :(得分:1)
答案 1 :(得分:0)
使用此:
$intersect = array_uintersect($array1, $array2, 'compareDeepValue');
print_r($intersect);
function compareDeepValue($val1, $val2)
{
return strcmp($val1['name'], $val2['name']);
}
答案 2 :(得分:0)
请试试这个:
$array1 = array("5","26","38","42");
$array2 = array("15","36","38","42");
$result = array_intersect($array1, $array2);
print_r($result);