How to pass a variable number of parameters to a function in PHP

前端 未结 3 711
暗喜
暗喜 2021-01-28 03:33

I have this multidimensional array (called $values):

Array
(
    [0] => Array
        (
            [0] => 5
            [1] => 2
            [2] =>          


        
相关标签:
3条回答
  • 2021-01-28 04:10
    function diff() {
        $args = func_get_args();
    
        // $args how has all the arrays you passed in.
    }
    
    0 讨论(0)
  • 2021-01-28 04:21

    Not sure if this is what you want, as I didn't read all of that, but check out:

    call_user_func_array('array_diff', $values)
    

    Maybe that's what you want.

    0 讨论(0)
  • 2021-01-28 04:27

    Instead of

    ${'arr'.$cnt}[] = ...
    

    use

    $arr[$cnt][] = ...
    

    Problem solved. :)

    There's no need for variable variables when what you're really looking for is an array.

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