Factorial of a number in PHP

Prev Tutorial Next Tutorial

Factorial of a number in PHP

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. But here we write program; how to print factorial of any number in php.

Example of Factorial

5!= 5 * 4 * 3 * 2 * 1 = 120

Factorial of a number in PHP


$num = 4;
$factorial = 1;
for ($x=$num; $x>=1; $x--) 
  $factorial = $factorial * $x;
echo "Factorial of $num is $factorial";



Factorial of 4 is 24

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements