Tuesday, 4 June 2013

Generate factorial of a number in php

The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n.

The factorial operation is encountered in many different areas of mathematics, notably in combinatorics, algebra and mathematical analysis.

<?php 
     $a = 1;
     for($i = 4; $i > 0; $i--){
         $a *= $i;
     }
     echo $a;
?> 
Output is: 24

2 comments: