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