passing a php function a variable amount of parameters*
Here is a php function:
mysqli_stmt_bind_param($statement, "s", ...variable amount of parameters...);
It will accept a variable amount of parameters you can review the documentation here - php.net. Obviously I can't type in $param1
, $param2
, $param3
... be开发者_Python百科cause I don't know many there will be. It is decided after run-time.
As far as I know, you can use call_user_func_array()
with any valid callback - so that includes PHP functions;
A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs such as: array(), echo(), empty(), eval(), exit(), isset(), list(), print() or unset().
Since call_user_func_array()
is using a callback as its first parameter, you can use any function you want. For example:
php > echo date('r', time());
Mon, 12 Sep 2011 00:37:52 +0300
php > echo call_user_func_array('date', array('r', time()));
Mon, 12 Sep 2011 00:38:23 +0300
So, you can call_user_func_array()
as follows:
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($statement, "s"), $params));
func_get_args();
精彩评论