Created
March 2, 2013 01:49
-
-
Save jveldboom/5069263 to your computer and use it in GitHub Desktop.
PHP Add Ordinal Number Suffix (1st, 2nd, 3rd....)
http://www.if-not-true-then-false.com/2010/php-1st-2nd-3rd-4th-5th-6th-php-add-ordinal-number-suffix/
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
<?php | |
function addOrdinalNumberSuffix($num) { | |
if (!in_array(($num % 100),array(11,12,13))){ | |
switch ($num % 10) { | |
// Handle 1st, 2nd, 3rd | |
case 1: return $num.'st'; | |
case 2: return $num.'nd'; | |
case 3: return $num.'rd'; | |
} | |
} | |
return $num.'th'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment