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);
                Since PHP-5.6 you can use a variadic reference:
function test(&...$args) {
    foreach ($args as &$arg) {
        $arg .= 'baz';
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With