Get Factorial Of A Given Number In Php

As you already knew that how factorial works in mathamatics if not then follow this link Click Here. We are going to write the code that will take a number as input and show the factorial of it. I’ts very simple. Follow the code below.

Code Example:

<form method="post">
<input type="number" name="txt" value="<?php echo $_POST['txt']; ?>" /><br />
<input type="submit" name="sbt" />
</form>
<?php 
if (isset($_POST['sbt']))
{
	$num = $_POST['txt'];
	$fac = 1;
			for ($num ; $num > 0 ; $num--){
					$fac *= $num;
				}
				echo "Factorial is ".$fac;
	
}

?>

Result:

factorial