Skip to content

Instantly share code, notes, and snippets.

@Kiwipup
Created September 12, 2018 23:46
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 Kiwipup/a5e77b39f159813b31ebfa0955e4332b to your computer and use it in GitHub Desktop.
Save Kiwipup/a5e77b39f159813b31ebfa0955e4332b to your computer and use it in GitHub Desktop.
First factorial in PHP
<?php
function FirstFactorial($num) {
// code goes here
//when the value of $num is less than or equal to 1, the function will terminate
if($num <= 1){
return 1;
}
/* the function will call itself repeatedly, each time multiplying the value
of $num by its own value -1 until the condition of the
previous if statement becomes true */
else{
return $num * FirstFactorial($num -1);
}
}
// keep this function call here
echo FirstFactorial(fgets(fopen('php://stdin', 'r')));
?>
@MatthewGidcomb
Copy link

Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment