CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: max(four, five)?
(Example: nine)

The Note You're Voting On

ayon at hyurl dot com
8 years ago
One way to call a anonymous function recursively is to use the USE keyword and pass a reference to the function itself:

<?php
$count
= 1;
$add = function($count) use (&$add){
$count += 1;
if(
$count < 10) $count = $add($count); //recursive calling
return $count;
};
echo
$add($count); //Will output 10 as expected
?>

<< Back to user notes page

To Top