Skip to content

Instantly share code, notes, and snippets.

@isalmanhaider
Created July 20, 2024 17:39
Show Gist options
  • Save isalmanhaider/020a19617eb19955a9bf2297921e5313 to your computer and use it in GitHub Desktop.
Save isalmanhaider/020a19617eb19955a9bf2297921e5313 to your computer and use it in GitHub Desktop.
code to determine the ordinal suffix for a given integer
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