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

$number = 5;
$result = factorial($number);

echo "Factorial of $number is $result"; // Output: Factorial of 5 is 120

Leave a Reply

Your email address will not be published. Required fields are marked *