Last active
October 30, 2025 17:03
-
-
Save UtmostCreator/1dd490493fd0137d40ab0c97db17f83f to your computer and use it in GitHub Desktop.
recursion function and its own stack frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function rDemo($n, $level = 1): void { | |
| $indent = str_repeat(" ", $level - 1); | |
| echo $indent . ' => Entering level ' . $level . "(n={$n})" . PHP_EOL; | |
| if ($n <= 0) { | |
| echo $indent . "Base case reached at level " . $level . " (n = " . $n . ")" . PHP_EOL; | |
| return; | |
| } | |
| rDemo($n - 1, $level + 1); | |
| echo $indent . ' <= Returning from level ' . $level . "(n={$n})" . PHP_EOL; | |
| } | |
| rDemo(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment