3
In php, we can create recursive functions as follows.
function quack($quack = 1)
{
if ($quacks >= 1) {
echo "Quack";
$quack--;
quack($quacks);
}
}
Or, in case of avoiding problem with "renaming" the function.
function quack($quack = 1)
{
$func = __FUNCTION__;
if ($quacks >= 1) {
echo "Quack";
$quack--;
$func($quacks);
}
}
But, and when it comes to anonymous functions?
Example:
$quack = function ($quacks)
{
if ($quacks >= 1) {
echo "Quack";
$quacks--;
// como chamo $quack aqui?
}
}
How could I make the function anonymous $quack
in a recursive function?
Let’s see if someone kills this charade :)
– Wallace Maxters