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?

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

call_user_func_array('array_intersect', $bigArray); this also works for me
@SolimanMahmoudSoliman yes, before PHP 5.6, that was the standard way to do this. You can check out the RFC for more info: wiki.php.net/rfc/argument_unpacking, specifically the "Advantages over call_user_func_array" section.
1
call_user_func_array('array_intersect', $bigArray);

this works for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.