This is another School / College fun program which is mostly been used in School lab to teach the basics of PHP such as if condition, for loop, multiplication, etc.,

So what is factorial? (if you don’t know already)

Multiplying given integer with the sequence of descending positive integers.

For example,  The value of 5! is 120.
which is, 5 x 4 x 3 x 2 x 1  =  120

So, In this tutorial you are going to see you how to write a PHP program to find the n! using for loops!


See the program here,

Read the comments in the program to understand how it is working.


I have also given an Online demo of this above PHP factorial program, see it here:


Enjoy the day!

Related Posts

3 thoughts on “Factorial Program in PHP

  1. hello why are you using same variable in $fact
    this my code

    for ($i = 1; $i <= $num; $i++){

    $fact = $facts * $i;

    echo $fact . "”;
    when i change it it’s not work explain it

Leave a Reply