简体   繁体   中英

pass arguments to a function php

Is it possible to convert an array to a list of elements without using list?


this works well

list($arg_a,$arg_b) = array($foo,$bar);
myfunction($arg_a,$arg_b);

but I'm looking for something similar to that:

$array = array($foo,$bar);
myfunction(php_builtin_function(array($foo,$bar)));

obviusly I can't edit that function!

function myfunction($param_a,$param_b){
    ...
    }

As mentioned in comments, here's what you need:

call_user_func_array('myfunction', php_builtin_function(array($foo,bar)));

Docs

That said, it would be more readable to use list :

$result = php_builtin_function(array($foo,$bar));
list($arg_a, $arg_b) = $result;
myfunction($arg_a, $arg_b);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM