Antonino Bonumore
Antonino Bonumore

Reputation: 797

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){
    ...
    }

Upvotes: 0

Views: 77

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324600

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);

Upvotes: 1

Related Questions