Example #1
0
function FirstFactorial($num)
{
    $total = 0;
    if ($num == 1) {
        //factorial can't be brought any lower
        return 1;
    } else {
        //level of recursion of current number
        //multiplied by factorial of number one less
        return $num * FirstFactorial($num - 1);
    }
}
Example #2
0
<?php

/*
	Have the function FirstFactorial(num) take the num parameter being passed and return the factorial of it 
	(ie. if num = 4, return (4 * 3 * 2 * 1)). For the test cases, the range will be between 1 and 18. 
*/
function FirstFactorial($num)
{
    $s = 1;
    for ($i = 1; $i <= $num; $i++) {
        $s = $s * $i;
    }
    return $s;
}
echo FirstFactorial(4);