Serguei Fedorov
Serguei Fedorov

Reputation: 7943

Passing parameters with call_user_func?

Is there a way to call a function using call_user_func and pass it parameters? For instance I have

function test($args)
{
    echo "I DID IT!";
}

however I cannot call this function because it has a paramter which is not being passed by

call_user_func("test");

is there a way to call the function and provide parameters to it? (for instance, the ability to pass in a list arguments)? Any help is greatly appreciated!

Upvotes: 26

Views: 37922

Answers (2)

Francis Avila
Francis Avila

Reputation: 31651

If you were to read the documentation you would see that call_user_func() accepts a variable number of arguments:

call_user_func('test', 'argument1', 'argument2');

You can also use call_user_func_array('callback', array('array','of','arguments')).

Upvotes: 42

Dreen
Dreen

Reputation: 7236

Use call_user_func_array, you can supply a list of parameters as array.

Upvotes: 20

Related Questions