Find common values in multiple arrays with PHP

后端 未结 1 653
温柔的废话
温柔的废话 2020-11-27 07:30

I need to find common values in multiple arrays. Number of arrays may be infinite. Example (output from print_r)

Array1
(
    [0] => 118
            


        
相关标签:
1条回答
  • 2020-11-27 08:03

    array_intersect()

    $intersect = array_intersect($array1,$array2,$array3);
    

    If you don't know how many arrays you have, then build up an array of arrays and user call_user_func_array()

    $list = array();
    $list[] = $array1;
    $list[] = $array2;
    $list[] = $array3;
    $intersect = call_user_func_array('array_intersect',$list);
    
    0 讨论(0)
提交回复
热议问题