Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created February 11, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NEbere/0e5dd799a9607de1ea08 to your computer and use it in GitHub Desktop.
Save NEbere/0e5dd799a9607de1ea08 to your computer and use it in GitHub Desktop.
The factorial of a given number
<?php
function factorial($n) {
$factorial = 1;
for($i = $n; $i >= 1; $i--){
$factorial = $factorial * $i;
}
echo "Factorial of $n is $factorial";
}
//calling the function
factorial(5);
//returns 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment