Last active
August 29, 2015 14:09
-
-
Save johnabela/6d44fd7051923e12ca64 to your computer and use it in GitHub Desktop.
Add Ordinal Text (st/nd/th) To Integer
This file contains 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
// | |
// | |
/////////////////////////////////////////////////////////////////////// | |
// intToOrdinal() | |
// | |
// - Description: | |
// Add Ordinal Text To Integer | |
// | |
// - Usage: | |
// $str_return = intToOrdinal($number); | |
// | |
// - Variables: | |
// $number = integer/number to apply Ordinal text too | |
// | |
// - Author: | |
// Iacopo - http://stackoverflow.com/a/3110033/797620 | |
/////////////////////////////////////////////////////////////////////// | |
function intToOrdinal($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) ? $number . $ends[$number % 10] : $number; | |
} | |
} | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment