简体   繁体   中英

How can I compute the intersection of an unknown number of arrays in php?

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
        )

)

试试call_user_func_array

call_user_func_array('array_intersect', $your_array_here);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM