1

I've been looking but unfortunately not found anything useful.

I have a function

function myFunc ($param1, $param2){ ...

I need to call that function but I have the parameters in an array

$params = [$param1, $param2]

Is there any way of doing something like ...[] (like in Js) ?

Note: I can not do

myFunc($params[$param1], $params[$param2]);
0

2 Answers 2

6

Since php5.6 there's a ... syntax:

myFunc(...$params);

And of course, call_user_func_array still exists and works both in php5 and php7:

call_user_func_array('myFunc', $params);
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the function call_user_func_array documentation: http://php.net/manual/en/function.call-user-func-array.php

$params = [$param1, $param2]

function myFunc ($param1, $param2){
    echo $param1;
    echo $param2;
}

call_user_func_array('myFunc', $params);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.