0

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?

2 Answers2

3

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

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
1
$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;
}
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42