Quick Search:
 
 PHP Code: Ordinalize (Suffix) Numbers Jump to:  
Category: >> PHP Code >> Ordinalize (Suffix) Numbers  

<< lastnext >>

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;
}
}
}
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org