Today, I read a piece of code and used many call_user_func_array () functions. At the beginning, they were very confused. Later I found through the manual that the call_user_func_array () function is still very useful, so the call_user_func_array () function usage in PHP is described in a simple code example.
Today, I read a piece of code and used many call_user_func_array () functions. At the beginning, they were very confused. Later I found through the manual that the call_user_func_array () function is still very useful, so the call_user_func_array () function usage in PHP is described in a simple code example.
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 () example
The Code is as follows:
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 ));
?>
The Code is as follows:
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)
?>