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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

@AbraCadaver, What does it means??
You are doing a great job, Top PHP Answerer last 30 Days.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.