如何可变数量的参数传递给在PHP函数 [英] How to pass a variable number of parameters to a function in PHP

查看:151
本文介绍了如何可变数量的参数传递给在PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个多维数组(称为$值):

I have this multidimensional array (called $values):

Array
(
    [0] => Array
        (
            [0] => 5
            [1] => 2
            [2] => 5
            [3] => 6
        )

    [1] => Array
        (
            [0] => 3
            [1] => 4
            [2] => 5
            [3] => 6
        )

    [2] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 4
            [3] => 5
        )

    [3] => Array
        (
            [0] => 9
            [1] => 5
            [2] => 3
            [3] => 2
        )
)

我想用和array_diff PHP函数这个多维数组的每一个元素(数组)之间来计算差异。我想的第一件事就是到多维数组为单个阵列,这种分裂:

I want to calculate the diff between every element (array) of this multidimensional array using array_diff PHP function. The first thing I've thought is to split the multidimensional array into single arrays with this:

for($cnt = 0; $cnt < count($values); $cnt++){
        for($cntB = 0; $cntB < 4; $cntB++){
            ${'arr'.$cnt}[] = $values[$cnt][$cntB];
        }
    }

这之后,我有几个阵列名为 $ ARR1 $ ARR2 ,等等。由于阵列的尺寸 $值可能会有所不同(它将)我不能找到一种方法,所有生成的单数组传递给函数和array_diff

After this I have several arrays called $arr1, $arr2, and so on. Since the dimension of the array $values may vary (and it will) I can't find a way to pass all the generated single arrays to the function array_diff,

有什么想法?

先谢谢了。

推荐答案

不知道这是你想要的,因为我没看过所有这一切,但检查出来:

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.

这篇关于如何可变数量的参数传递给在PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆