Jump to content

Making a list


MrXander

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.