Skip to content

Instantly share code, notes, and snippets.

@meadsteve
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save meadsteve/8917648 to your computer and use it in GitHub Desktop.
Save meadsteve/8917648 to your computer and use it in GitHub Desktop.
Totally legitimate ordinal number creator
<?php
function intToString($int) {
$first = 'second';
$second = 'third';
$third = 'forth';
$forth = 'fifth';
$dollarer = function ($count) { return ($count > 1) ? str_repeat('$', min($count - 1, 4)) : str_repeat('$', 5); };
if ($int > 5 && $int < 10) {
$dollars = "$$$$$";
$fifth = array('fifth', 'sixth', 'seventh', 'eighth', 'ninth');
goto woo;
}
else {
$dollars = $dollarer($int);
$fifth = 'first';
goto ahh;
}
woo:
$array = eval("return " . $dollars . 'first;');
return $array[$int - 5];
ahh:
return eval("return " . $dollars . 'first;');
}
@MarkMaldaba
Copy link

Good, but I spotted a few issues which I've fixed in my fork.

  • Always avoid literal numbers as it's very hard to tell what they refer to.
  • If statements very old-fashioned (they've existed ever since PHP 3!!!). Modern PHP uses switch.

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