I have city array like this
$city = array(
array(1, 2, 3, 4),
array(1, 2, 3, 4, 5),
array(2, 3, 4, 5),
);
I want result like this:
$resulted_array=array(2,3,4);
I want that without using recursive function
I have city array like this
$city = array(
array(1, 2, 3, 4),
array(1, 2, 3, 4, 5),
array(2, 3, 4, 5),
);
I want result like this:
$resulted_array=array(2,3,4);
I want that without using recursive function
For PHP 5.6 and above, you can directly use array_intersect() with the ... token (also called splat operator in other languages):
$city = array(
array(1, 2, 3, 4),
array(1, 2, 3, 4, 5),
array(2, 3, 4, 5),
);
$inter = array_intersect(...$city);
Performance-wise this is much faster than call_user_func_array()
This is working example for me -
<?php
$arr = array(
array(1, 2, 3, 4),
array(1, 2, 3, 4, 5),
array(2, 3, 4, 5),
);
$intersect = call_user_func_array('array_intersect', $arr);
print_r($intersect);
?>
O/P
Array
(
[1] => 2
[2] => 3
[3] => 4
)
Function was not required. Only above code will work for your requirement.