Skip to content

Instantly share code, notes, and snippets.

@saxenanurag
Created April 22, 2014 19:55
Show Gist options
  • Save saxenanurag/11192198 to your computer and use it in GitHub Desktop.
Save saxenanurag/11192198 to your computer and use it in GitHub Desktop.
add 'rd or 'th or 'st dependant on number
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';
}
@saxenanurag
Copy link
Author

11, 12 and 13 are special cases -

11th, 12th 13th instead of 11st, 12nd, 13rd

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