phparraysparametersmethod-parameters

How to Convert Array to Params of Method?


I need to pass params (like: 'param1', 'param2', 'param3') to the method... but I have array of params (like: array('param1', 'param2', 'param3')). How to convert array to params?

function foo(array $params) {

    bar(
        // Here should be inserted params not array.
    );

}

Solution

  • Use the function call_user_func_array.

    For example:

    call_user_func_array('bar', $params);