Useful to create a title while iterating an array, or referencing the nth entity in some text.
1 -> 1st
2 -> 2nd
31 -> 31st
function nth($number) {
if ($number % 10 == 1) {
return $number.'st';
} elseif ($number % 10 == 2) {
return $number.'nd';
} else {
return $number.'th';
}
}
Comments
Comment #1
sradomski commentedHehe - Forgot the 3rd case!
d'oh
Comment #2
nancydruCan you, please, supply this as a real patch - and in Drupal coding standards? Also, we require documentation to apply any new function.
Comment #3
nancydruNot submitted as a patch; no documentation.