PHP将数组值解析为函数

Cal*_*lum 3 php arrays

好的,所以我有一个带有2个必需参数的函数,然后它也必须有许多可选参数.

function example($a,$b, $username, $email) {
    // code
}
Run Code Online (Sandbox Code Playgroud)

我的可选参数数据来自一个数组

$x = array('joeblogs', 'joe@blogs.com');
Run Code Online (Sandbox Code Playgroud)

我怎么能解析这些?请记住,每次都可能需要该函数来解析一组不同的参数.

一个例子是CakePHP,您可以指定所需的操作参数

Jez*_*Jez 5

像这样的东西?

$a = 'a';
$b = 'b';
$x = array('joeblogs', 'joe@blogs.com');

$args = array_merge(array($a, $b), $x);

call_user_func_array('example', $args);
Run Code Online (Sandbox Code Playgroud)

请参见http://php.net/manual/en/function.call-user-func-array.php