Write a factorial program using for loop in php

Description:

Write a program to calculate factorial of a number using for loop in php.

<?php
$num = 3;
$factorial = 1;
 
for ($x=$num; $x>=1; $x--)
{
    $factorial = $factorial * $x;
}
 
echo "The factorial of $num is $factorial";
?>
Tutorials Class - Output Window

The factorial of 3 is 6


Learn more about the similar topics:
Tutorials
PHP Loops
Exercises & Assignments
Write a program to count 5 to 15 using PHP loop
Write a factorial program using for loop in php
Factorial program in PHP using recursive function
Write a program to create Chess board in PHP using for loop
Write a Program to create given pattern with * using for loop
Interview Questions & Answers
No Content Found.