Skip to content

Instantly share code, notes, and snippets.

@Sobak
Created December 28, 2014 21:56
Show Gist options
  • Save Sobak/7f3b1c6ffd951467005e to your computer and use it in GitHub Desktop.
Save Sobak/7f3b1c6ffd951467005e to your computer and use it in GitHub Desktop.
Innovative implementation of factorial. Result of boredom and too much free time.
<?php
function factorial($num) {
return eval('return '.implode(range(1, $num), '*').';');
}
// more readable form
function factorial2($num) {
$operation = implode(range(1, $num), '*');
return eval("return $operation;");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment