How can beginners understand and effectively use recursion in PHP?

Recursion in PHP is a technique where a function calls itself within its definition. Beginners can understand recursion by breaking down the problem into smaller parts and understanding how the function calls itself to solve these smaller parts. To effectively use recursion in PHP, it's important to have a base case that stops the recursive calls and to ensure that the function progresses towards the base case with each recursive call.

function factorial($n) {
    if ($n <= 1) {
        return 1;
    } else {
        return $n * factorial($n - 1);
    }
}

// Example usage
echo factorial(5); // Output: 120