Ordinalize (Suffix) Numbers

Description: Add suffix to number (1st, 2nd, 3rd, 4th…)

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

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.