MrXander Posted July 1, 2008 Share Posted July 1, 2008 Hi, Could someone point me in the way of a tutorial or code samples of how to make a list in php of one to fifty? By that, I don't mean a numerical list, I mean actually: One Two Three etc Any help would be appreciated. Thank you. Link to comment https://forums.phpfreaks.com/topic/112792-making-a-list/ Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 You will have to type that out unless you can find it already typed on Google. $numbers = array("One", "Two", "Three", [...]); Good luck! Link to comment https://forums.phpfreaks.com/topic/112792-making-a-list/#findComment-579288 Share on other sites More sharing options...
MrXander Posted July 1, 2008 Author Share Posted July 1, 2008 Are you sure? That would really suck... Link to comment https://forums.phpfreaks.com/topic/112792-making-a-list/#findComment-579298 Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Yep. You can do an array that just has the unique numbers that you need, though: $numbers = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"); Link to comment https://forums.phpfreaks.com/topic/112792-making-a-list/#findComment-579300 Share on other sites More sharing options...
sasa Posted July 1, 2008 Share Posted July 1, 2008 try <?php function num_to_word($num, $tri=0) { $ones = array("", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen"); $tens = array("", "", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety"); $triplets = array("", " thousand", " million", " billion"); $r = (int) ($num / 1000); $x = ($num / 100) % 10; $y = $num % 100; $str = ""; if ($x > 0) $str = $ones[$x] . " hundred"; if ($y < 20) $str .= $ones[$y]; else $str .= $tens[(int) ($y / 10)] . $ones[$y % 10]; if ($str != "") $str .= $triplets[$tri]; if ($r > 0) return convertTri($r, $tri+1).$str; else return $str; } for ($i = 1; $i<=50; $i++) $out[$i] = ucfirst(trim(num_to_word($i))); print_r($out); ?> Link to comment https://forums.phpfreaks.com/topic/112792-making-a-list/#findComment-579363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.