I've been trying to find a function which increments a counter using words. I know its possible using numbers with suffixes (i.e. 1st, 2nd, 3rd and so on). Here is a snippet of the code i've got:
function addOrdinalNumberSuffix($num) {
if (!in_array(($num % 100),array(11,12,13))){
switch ($num % 10) {
// Handle 1st, 2nd, 3rd
case 1: return $num.'st';
case 2: return $num.'nd';
case 3: return $num.'rd';
}
}
return $num.'th';
}
But is there a way to replicate this with words (i.e First, Second, Third, etc..)?
I'd expect it to be quite difficult (but not impossible) to create an infinite counter, but anything up to 20 would suffice.
Any help would be much appreciated.
Here's a link to a simple PHP function that shows how to handle this in a simple manner: http://webdeveloperblog.tiredmachine.com/php-converting-an-integer-123-to-ordinal-word-firstsecondthird/
The provided example only works into the fifties, but can easily be expanded upon to reach higher ranges.
Ordinals (English only), based on SIFE's answer:
Here goes some pseudo code to perhaps lead on a hopefully good way:
There is a class from PEAR package can do that:
Source.
Twenty isn't that much to hardcode. You'd just need an array, not a function.
The more direct answer is: There isn't a built in function that does what you're looking for.