1

I have the following array that contains other arrays:

$bigArray = [$array_one, $array_two, $array_three,.... ];

I want to array_intersect the inner arrays like so:

$intersect = array_intersect($array_one, $array_two, $array_three,....);

How do I handle it?

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • [check this for other options](https://stackoverflow.com/questions/38056228/get-intersection-of-a-multiple-array-in-php) – kofi_codes Apr 17 '18 at 15:37

2 Answers2

4

Like this:

$intersect = array_intersect(...$bigArray);

The ... operator, introduced in PHP 5.6, allows you to use an array to pass multiple function arguments.

It's also possible to do this with call_user_func_array, but argument unpacking offers some advantages over that approach.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • call_user_func_array('array_intersect', $bigArray); this also works for me – Soliman Mahmoud Soliman Apr 17 '18 at 15:35
  • 3
    @SolimanMahmoudSoliman yes, before PHP 5.6, that was the standard way to do this. You can check out the RFC for more info: https://wiki.php.net/rfc/argument_unpacking, specifically the "Advantages over call_user_func_array" section. – Don't Panic Apr 17 '18 at 15:38
1
call_user_func_array('array_intersect', $bigArray);

this works for me