array_intersect a variable amount of arrays

前端 未结 4 459
陌清茗
陌清茗 2021-01-13 17:30

I am creating a faceted search, and I\'m am trying to use array_intersect to compare the arrays and find the inputs that match.

The problem is that I wi

相关标签:
4条回答
  • 2021-01-13 17:40

    You can turn those array to a single array named $total_array by using array_combine(), then use array_intersect($full_array, $total_array). I hope this useful

    0 讨论(0)
  • 2021-01-13 17:55

    One can use:

    $intersect = array_intersect(...$fullArray);
    
    0 讨论(0)
  • 2021-01-13 18:01

    Try this:

    $fullArray = array($array1, $array2, $array3...);
    call_user_func_array('array_intersect', $fullArray);
    
    0 讨论(0)
  • 2021-01-13 18:03

    First of all, turn those arrays into an array of arrays. Then you can use array_reduce combined with array_intersect to reduce a variable amount of arrays down to one.

    0 讨论(0)
提交回复
热议问题