Add PHP ordinal suffix to Numbers
Function to add st, nd, rd and th to numbers in php
function numberSuffix($number) {
if(!in_array(($number % 100),array(11,12,13))) {
switch ($number % 10) {
case 1: return $number.'st';
case 2: return $number.'nd';
case 3: return $number.'rd';
}
}
return $number.'th';
if(!in_array(($number % 100),array(11,12,13))) {
switch ($number % 10) {
case 1: return $number.'st';
case 2: return $number.'nd';
case 3: return $number.'rd';
}
}
return $number.'th';
}
No comments:
Post a Comment