jschofield Posted April 25, 2007 Share Posted April 25, 2007 Hello fellow phpers, I have a quick question about a function that I cant remember. The function converts numbers 1 2 3 into first second third. Does anyone know this function name. It would be big help finish my script. Thanks everyone. Johnnie Link to comment https://forums.phpfreaks.com/topic/48538-solved-quick-question/ Share on other sites More sharing options...
AndyB Posted April 25, 2007 Share Posted April 25, 2007 Unless it's about dates, not numbers, that sounds like a home-brewed function (but I wouldn't be surprised if I were wrong - again) Link to comment https://forums.phpfreaks.com/topic/48538-solved-quick-question/#findComment-237613 Share on other sites More sharing options...
per1os Posted April 25, 2007 Share Posted April 25, 2007 It has to be home brewed, I searched around. It wouldn't be too hard to create, sounds like a fun little task =) interesting.... Link to comment https://forums.phpfreaks.com/topic/48538-solved-quick-question/#findComment-237620 Share on other sites More sharing options...
jschofield Posted April 25, 2007 Author Share Posted April 25, 2007 You guys are right. I checked with the guy that teaches me php and he had made it himself. I think it would be a ncie little function to have so I think I may try to build my own and post. Well at least try to build my own...haahaha. Thanks for all the help guys!! Johnnie Link to comment https://forums.phpfreaks.com/topic/48538-solved-quick-question/#findComment-237628 Share on other sites More sharing options...
per1os Posted April 25, 2007 Share Posted April 25, 2007 Here is my version of it. Cannot do below zero and nothing above 100...for now =) <?php function num_to_lit($num) { if ($num < 1) { return "cannot calculate below zero"; } $numArr = array(1 => "first", 2 => "second", 3 => "third", 4 => "fourth", 5 => "fifth", 6 => "sixth", 7 => "seventh", 8 => "eigth", 9 => "nineth", 10 => "tenth", 11 => "eleventh", 12 => "twelth", 13 => "thirteenth", 14 => "fourteenth", 15 => "fifteenth", 16 => "sixteenth", 17 => "seventeenth", 18 => "eighteenth", 19 => "nineteenth"); $tenArr = array( 20 => "twenty", 30 => "thirty", 40 => "fourty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"); if ($num < 20) { return $numArr[$num]; }else { $i=0; $nextKey = 30; foreach ($tenArr as $key => $val) { $i++; if ($num >= $key && $num < $nextKey) { if ($num == $key) { return $val . "th"; }else { $newNum = ($num - $key); return $val . $numArr[$newNum]; } } $nextKey += 10; } } } ?> Link to comment https://forums.phpfreaks.com/topic/48538-solved-quick-question/#findComment-237649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.