Call_user_func () and Call_user_func_array (), by passing in a string function, can invoke a custom function and support references, allowing the user to invoke a custom function and pass in a certain parameter:
1.Mixed Call_user_func (callable $callback [, Mixed $parameter [, mixed $ ...])
The first parameter is the custom function name, and the following argument is the function's argument, and the return value is the result of the custom function.
function Say ($wordecho$word;} Call_user_func (' Say ', ' Hello World '// output//hello World
Of course, you can also call methods in the class:
Classfunction SayHello ($word = ") { echo$word;}} // Note that it must be instantiated, unless it is a static $world New World (); Call_user_func ([$world, ' SayHello '], ' Hello World '// output Hello world
Note: The way the array is written above [], if the PHP version is below PHP5.4, use Array ()
2. Mixed Call_user_func_array (callable $callback, array $param _arr)
The call user func () is actually the same as the function, but only a slight difference in the parameters, this is actually from the name of the method can be seen out:
function Say ($wordecho$word;} Call_user_func_array // Note: The second parameter is the form of an array//output//hello World
Classfunction SayHello ($word = ") { echo$word;}} // Note that it must be instantiated, unless it is a static $world New World (); Call_user_func_array ([$world// Note: The second parameter is an array form//output Hello world
Call user func () and Call_user_func_array () Invoke Custom Function summary in PHP