php how to implode two dimensional array as arguments of array_intersect

81 views Asked by At

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?

2

There are 2 answers

0
Rudy David On BEST ANSWER

You can use call_user_func_array like this

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

0
Edjjj On

Another variant would be to use the "splat" operator in PHP.

array_intersct(...$array);

It would be more cleared than using call_user_func_array() soltion provided above.