Jump to content

Making a list


MrXander

Recommended Posts

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
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.