Call_user_func_array
(PHP 4> = 4.0.4, PHP 5)
Call_user_func_array -- call a User Function Given with an array of parameters
Description
Mixed call_user_func_array (callback function, array param_arr)
Call a user defined function given by function, with the parameters in param_arr. For example:
Example 1. call_user_func_array () ExampleCopyCodeThe Code is as follows: <? PHP
Function debug ($ var, $ Val)
{
Echo "*** debugging \ nvariable: $ var \ nvalue :";
If (is_array ($ Val) | is_object ($ Val) | is_resource ($ Val )){
Print_r ($ Val );
} Else {
Echo "\ N $ Val \ n ";
}
Echo "*** \ n ";
}
$ C = mysql_connect ();
$ Host = $ _ server ["SERVER_NAME"];
Call_user_func_array ('debug', array ("host", $ host ));
Call_user_func_array ('debug', array ("C", $ C ));
Call_user_func_array ('debug', array ("_ post", $ _ post ));
?>
Copy codeThe Code is as follows: <? PHP
Function Test ($ Str ){
Echo $ STR;
}
Call_user_func_array ("test", "No.1 www.chhua.com"); // output "No.1 www.chhua.com"
// Parameter description "the first parameter is the function name and the second parameter.
Class testclass {
Public Function write ($ Str ){
Echo $ STR;
}
}
Call_user_func_array (Array (testclass, write), "No.1 www.chhua.com"); // when calling with a class, use array (), array (Class Name, method name)
?>