Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
Created June 5, 2014 10:52
Show Gist options
  • Save dannyockilson/79865d873bf8575bd52c to your computer and use it in GitHub Desktop.
Save dannyockilson/79865d873bf8575bd52c to your computer and use it in GitHub Desktop.
Add "Ordinal Suffix" to a number (ie 1->1st)
function iadw_get_ordinal_suffix($number){
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if (($number %100) >= 11 && ($number%100) <= 13)
$abbreviation = $number. 'th';
else
$abbreviation = $number. $ends[$number % 10];
return $abbreviation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment