duanquanhan2333 2011-03-23 08:04
浏览 59
已采纳

如何将可变数量的参数传递给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
        )
)

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];
        }
    }

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,

Any thoughts?

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • douzang7928 2011-03-23 08:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来