Let's start with someone else's example:
The Call_user_func function is similar to a particular method of calling a function, using the following method:
Copy Code code as follows:
function A ($b, $c)
{
Echo $b;
Echo $c;
}
Call_user_func (' A ', "111", "222");
Call_user_func (' A ', "333", "444");
displaying 111 222 333 444
?>
Call the internal method of the class is strange, incredibly with array, do not know how to consider the developer, of course, save the new, but also full of innovative:
Copy Code code as follows:
Class A {
Function B ($c)
{
Echo $c;
}
}
Call_user_func (Array ("A", "B"), "111");
Show 111
?>
The Call_user_func_array function is very similar to the call_user_func, except that it passes the argument in a different way, making the parameter structure clearer:
Copy Code code as follows:
function A ($b, $c)
{
Echo $b;
Echo $c;
}
Call_user_func_array (' A ', Array ("111", "222"));
Showing 111 222
?>
The Call_user_func_array function can also invoke methods within the class
Copy Code code as follows:
Class ClassA
{
function BC ($b, $c) {
$BC = $b + $c;
Echo $BC;
}
}
Call_user_func_array (Array (' ClassA ', ' BC '), Array ("111", "222"));
Show 333
?>
Both the Call_user_func function and the Call_user_func_array function support references, which tend to be more functional consistent with normal function calls:
Copy Code code as follows:
function A ($b)
{
$b + +;
}
$c = 0;
Call_user_func (' A ', $c);
echo $c//Show 1
Call_user_func_array (' A ', Array ($c));
echo $c//Show 2
Another: Both the Call_user_func function and the Call_user_func_array function support references.
Copy Code code as follows:
<?php
function increment (& $var)
{
$var + +;
}
$a = 0;
Call_user_func (' increment ', $a);
echo $a; 0
Call_user_func_array (' Increment ', array (& $a)); can use this instead
echo $a; 1
?>