Can you explode an array into function arguments?

Is it possible to have an array and pass it to a function as separate arguments?

$name = array('test', 'dog', 'cat'); $name = implode(',' $name); randomThing($name); function randomThing($args) { $args = func_get_args(); // Would be 'test', 'dog', 'cat' print_r($args); } 
+6
source share
2 answers

Not. This is for call_user_func_array() .

+11
source

Starting with PHP 5.6 you can use ... to pass an array as arguments to a function. See an example from the PHP documentation:

 function add($a, $b) { return $a + $b; } echo add(...[1, 2])."\n"; $a = [1, 2]; echo add(...$a); 
0
source

Source: https://habr.com/ru/post/913868/


All Articles