Skip to content

Instantly share code, notes, and snippets.

@michelmany
Created October 1, 2020 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelmany/0c34a89468e503351c67946efdff8a65 to your computer and use it in GitHub Desktop.
Save michelmany/0c34a89468e503351c67946efdff8a65 to your computer and use it in GitHub Desktop.
Display numbers with ordinal suffix in PHP
/**
* Set Ordinal Numbers
*
* @param [type] $number
* @return void
*/
function ordinal($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if ((($number % 100) >= 11) && (($number%100) <= 13))
return $number. 'th';
else
return $number. $ends[$number % 10];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment