Snippet Name: Ordinalize (Suffix) Numbers
Description: Add suffix to number (1st, 2nd, 3rd, 4th...)
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009
|
<?PHP
FUNCTION ordinalize($number) {
IF (IN_ARRAY(($number % 100),RANGE(11,13))){
RETURN $number.'th';
}ELSE{
SWITCH (($number % 10)) {
CASE 1:
RETURN $number.'st';
BREAK;
CASE 2:
RETURN $number.'nd';
BREAK;
CASE 3:
RETURN $number.'rd';
DEFAULT:
RETURN $number.'th';
BREAK;
}
}
}
?> |