How can I compute the intersection of an unknown number of arrays in php?
-
19-03-2021 - |
Question
I have an array of arrays, and I want to find the intersection of the contained arrays.
My problem is that the array_intersect function requires the arrays to be explicitly specified in the params. I cannot feed the function with my array-of-arrays.
What can I do?
Array
(
[0] => Array
(
[0] => 1
[1] => 1504
[2] => 2181
[3] => 488
[4] => 554
[5] => 1539
[6] => 494
[7] => 2022
)
[1] => Array
(
[0] => 51
[1] => 617
[2] => 651
[3] => 788
[4] => 799
[5] => 835
[6] => 863
[7] => 407
[8] => 650
[9] => 783
)
)
Solution
call_user_func_array('array_intersect', $your_array_here);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow