tags:

views:

92

answers:

1

I know I can do that using switch(), but still I wanted to know if there's any PHP function for that.

+7  A: 

From one to ten:

$numbers = array("zero" => 0, "one" => 1, "two" => 2, "three" => 3, "four" => 4, 
                 "five" => 5, "six" => 6,  "seven" => 7, "eight" => 8, 
                 "nine" => 9, "ten" => 10);

echo $numbers["nine"]; // 9 

Beyond that, it gets trickier (except if you want to type out a very large list, of course.)

Pekka
Or use an associative array `'one' => 1 ` so you don't have to search...
Felix Kling
@Felix yeah. This was done with converting it back in mind, but good point. Editing.
Pekka
And you excluded zero because...?
Eric
@Eric *insert complicated mathematico-philosophical explanation here* I forgot.
Pekka