array_intersect() with dynamic length of arguments

后端 未结 2 1294
名媛妹妹
名媛妹妹 2020-12-11 08:18

I\'ve got an array of arrays that may have a different count of elements when the script is run.

$strict = [
    [0] => [\'one\', \'two\', \'three\', \'f         


        
相关标签:
2条回答
  • 2020-12-11 08:56

    You can use call_user_func_array:

    Call a callback with an array of parameters

    So your callback would be array_intersect, and you could pass your array like this:

    $result = call_user_func_array('array_intersect', $strict);
    
    0 讨论(0)
  • 2020-12-11 09:15

    You can take advantage of modern PHP's array packing/unpacking features - aka variadics, or the so-called "splat" (...) operator - as well:

    $result = array_intersect(...$strict);
    
    0 讨论(0)
提交回复
热议问题