Files
developer-roadmap/roadmaps/php/content/recursion@D9ybK5INH5zSOcYMb5ZPi.md
Arik Chakma 274082fd77 feat: clean roadmap content and sync scripts (#10181)
* refactor: clean to roadmap content

* refactor: move shared helpers into scripts/lib
2026-07-28 05:45:17 +06:00

18 lines
905 B
Markdown

# Recursion
Recursion, as it applies to PHP, refers to a function that calls itself to solve a problem. A recursive function distinguishes itself by solving small parts of the problem until it resolves the main issue. Think of it as breaking down a task into smaller tasks that are easier to solve. However, careful design is needed to ensure the recursive function has a clear stopping point, or else it can result in an infinite loop. Here's a quick example of a simple recursive function in PHP:
function countDown($count) {
echo $count;
if($count > 0) {
countDown($count - 1);
}
}
countDown(5);
In this example, the function `countDown` calls itself until the count hits zero, displaying numbers from 5 to 0.
Visit the following resources to learn more:
- [@official@Functions - Recursion](https://www.php.net/manual/en/language.functions.php)