<?php
$num = 3;
$factorial = 1;
if($num != 0) {
for($i = $num; $i>=1; $i--) {
$factorial = $factorial * $i;
}
}
else {
$factorial = 1;
}
echo "Factorial of $num is $factorial";
?>