What is the best practice for handling return values in recursive PHP functions?

When dealing with recursive PHP functions, it is important to handle return values properly in order to ensure the correct result is returned at each level of recursion. One common approach is to pass the return value back up the call stack by returning it from the recursive function and then using it in subsequent recursive calls or in the final return statement.

function recursiveFunction($input) {
    // Base case
    if ($input <= 0) {
        return 0;
    }

    // Recursive case
    $result = $input + recursiveFunction($input - 1);

    return $result;
}

// Example usage
$input = 5;
$output = recursiveFunction($input);
echo $output; // Output: 15