Created
January 11, 2016 05:00
-
-
Save softon/2b89990d5836d9b67a72 to your computer and use it in GitHub Desktop.
A simple function to return the ordinal of any number
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
<?php | |
/** | |
* A simple function to return the ordinal of any number | |
* E.g: number = 1 => Ordinal = st | |
* E.g: number = 23 => Ordinal = rd | |
* | |
* @param int $number | |
* @return string | |
*/ | |
function getOrdinal($number){ | |
$n = $number%10; | |
switch($n){ | |
case 1: | |
return 'st'; | |
case 2: | |
return 'nd'; | |
case 3: | |
return 'rd'; | |
default: | |
return 'th'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment