How would i use array_intersect() with the arrays

2019-08-22 11:46发布

问题:

I have a dynamic amount of arrays in a specific array.
Let's call this specific array: FatherArray

This FatherArray has a dynamic amount of arrays in it, right now for example: Child1Array,Child2Array. Next time it gets called it could have more or less than those 2 Child(number)Arrays.

So I want to use the function array_intersect() with the arrays (children) of FatherArray as parameters, so like array_intersect(Child1Array,Child2Array).
I don't have a clue how i could do this dynamically, neither could I find anything about it, any help would greatly be appreciated

回答1:

If your version is reasonably new (v5.6):

array_intersect(...$FatherArray);

Otherwise:

call_user_func_array('array_intersect', $FatherArray);

Demo: see comment by Mark (thx @MarkBaker)