如何在PHP中引用传递参数无限 [英] how to pass unlimited arguments by reference in php

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

问题描述

我有一个具有我从func_get_args得到()ARGS无限数量的PHP函数。我有一个参数(改变字符串或做某事)一些操作,我想这是像通过引用传递参数。这可能吗?

例如:

  $测试='富';
$ TEST2 ='吧';功能测试(){
    的$ args = func_get_args();
    的foreach($ ARGS为$ ARG)
        $ ARG ='巴兹'。
}测试(测试$,$ TEST2);


解决方案

作为<一回答href=\"http://stackoverflow.com/questions/1925253/php-variable-length-argument-list-by-reference\">PHP:参照可变长度参数列表?,没有在PHP没有办法可变长度相结合,并通过引用函数的参数传递。相反,挂答案使用宣布100的破解&放大器; argx s,则使用 get_num_args()要弄清楚有多少人真正使用。恭喜你,你找到了一个特别难的角落在PHP;)

I have php function that has an unlimited number of args which I am getting from func_get_args(). I have some operations with arguments (changing string or doing something) and I want this to be like a passing argument by reference. is it possible?

example:

$test = 'foo';
$test2 = 'bar';

function test(){
    $args = func_get_args();
    foreach($args as $arg)
        $arg .= 'baz';
}

test($test, $test2);

解决方案

As answered in PHP: variable-length argument list by reference?, there is no way in PHP to combine variable-length and pass by reference function arguments. Instead, the linked answer uses a hack of declaring 100 &argxs, then using get_num_args() to figure out how many were actually used. Congratulations, you found a particularly hard corner in PHP ;)

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

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