Return to Snippet

Revision: 4714
at January 17, 2008 13:25 by ajbatac


Initial Code
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;
}
}
}

Initial URL

                                

Initial Description

                                

Initial Title
A function to add a prefix to numbers ex. 1st 2nd 3rd 4th 5th

Initial Tags

                                

Initial Language
PHP