I've an array like this:
$params = ["Hello" => "Hello World", "Text" => "This is a text"];
And I want to call function:
myFunction("Hello World", "This is a text");
How can I do that?
I've an array like this:
$params = ["Hello" => "Hello World", "Text" => "This is a text"];
And I want to call function:
myFunction("Hello World", "This is a text");
How can I do that?
You're looking for call_user_func_array()
:
call_user_func_array('myFunction', $params);
Or if you have PHP 5.6+, you can use the ...
operator:
myFunction(...$params);
NOTE: This only works with numeric arrays, not associative arrays
$params = ["Hello" => "Hello World", "Text" => "This is a text"];
Using call_user_func_array
call_user_func_array('myFunction', array_values($params));
Also you can do this:
myFunction($params['Hello'], $params['Text']);
function myFunction($h, $t){
echo $h." - ".$t;
}