Skip to content
Advertisement

php how to implode two dimensional array as arguments of array_intersect

I have an array of arrays like below

$array = [
  0 => [10, 20, 50],
  1 => [20, 30, 50],
  2 => [10, 20, 60],
]

and I want to give them as arguments of array_intersect like below

array_intersct($array[0], $array[1], $array[2])

but this is not dynamic do you have better suggestions?

Advertisement

Answer

You can use call_user_func_array like this

$intersect = call_user_func_array('array_intersect',$array);

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement