Created
April 22, 2014 19:55
-
-
Save saxenanurag/11192198 to your computer and use it in GitHub Desktop.
add 'rd or 'th or 'st dependant on number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ordinal_suffix($num){ | |
if($num < 11 || $num > 13){ | |
switch($num % 10){ | |
case 1: return 'st'; | |
case 2: return 'nd'; | |
case 3: return 'rd'; | |
} | |
} | |
return 'th'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
11, 12 and 13 are special cases -
11th, 12th 13th instead of 11st, 12nd, 13rd