How to pass array as multiple parameters to function?

Blackbeard picture Blackbeard · Apr 27, 2010 · Viewed 11k times · Source

I have a parameters array:

$params[1] = 'param1';
$params[2] = 'param2';
$params[3] = 'param3';
...
$params[N] = 'paramN';

I have a caller to various functions:

$method->$function( $params );

How can I parse the $params array, so multiple (and unlimited) parameters can be passed to any function:

$method->$function( $params[1], $params[2], ..., $params[N] );

The idea is to utilize the url rewrite like this:

http://domain.com/class/method/parameter/parameter/parameter/...

Answer

Yacoby picture Yacoby · Apr 27, 2010

You need to use call_user_func_array

call_user_func_array( array($method, $function), $params);