-1

I need to compare all first levels items of a muli-dimensional array and get the intersection values.. But the array doesn't have a fixed number arrays to compare with each other..

Here you have to explicit type each argument in array_intersect..

$list = [
  [0,1,2],
  [2,5],
  [-1,2]
];

$t = array_intersect($list[0], $list[1], $list[2]);
print_r($t);

But what if the $list array had 10 sub-arrays and I wanted to compare each and one of them?

3

2 Answers 2

3

You can use call_user_func_array (< 5.6) or arguments unpacking (>= 5.6)

call_user_func_array('array_intersect', $list);

array_intersect(...$list);
Sign up to request clarification or add additional context in comments.

Comments

2

Try using call_user_func_array:

call_user_func_array('array_intersect', $list);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.