Jump to content

[SOLVED] Quick Question


jschofield

Recommended Posts

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

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

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.