3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php # This script will cater for any integer amount between 0 and 999999 $amount = 920915; $tmpAmount = 0; $tmpAmount2 = 0; $divident = 100000; $output = ""; while (($amount > 0) && ($divident > 0)) { if ($amount >= $divident) { $tmpAmount = (int)($amount / $divident); if (strlen($output) > 0) { $output .= "&"; } switch($tmpAmount) { case 1: { $output.="amount/one"; break; } case 2: { $output .= "amount/two"; break; } case 3: { $output .= "amount/three"; break; } case 4: { $output .= "amount/four"; break; } case 5: { $output .= "amount/five"; break; } case 6: { $output .= "amount/six"; break; } case 7: { $output .= "amount/seven"; break; } case 8: { $output .= "amount/eight"; break; } case 9: { $output .= "amount/nine"; break; } } switch($divident) { case 100000: case 100: { $output .= "&amount/hundred"; $output .= "&amount/and"; $tmpAmount2 = substr($amount, 1, 2); if ($tmpAmount2 > 10) { $tmpAmount2 = substr($tmpAmount2, 0, 1) * 10; } switch($tmpAmount2) { case 1: { $output .= "&amount/and"; $output.="&amount/one"; break; } case 2: { $output .= "&amount/and"; $output .= "&amount/two"; break; } case 3: { $output .= "&amount/and"; $output .= "&amount/three"; break; } case 4: { $output .= "&amount/and"; $output .= "&amount/four"; break; } case 5: { $output .= "&amount/and"; $output .= "&amount/five"; break; } case 6: { $output .= "&amount/and"; $output .= "&amount/six"; break; } case 7: { $output .= "&amount/and"; $output .= "&amount/seven"; break; } case 8: { $output .= "&amount/and"; $output .= "&amount/eight"; break; } case 9: { $output .= "&amount/and"; $output .= "&amount/nine"; break; } case 10: { $tmpAmount2 = substr(($amount - ($divident * $tmpAmount)), 0, 2); switch($tmpAmount2) { case 10: { $output.="&amount/ten"; break; } case 11: { $output.="&amount/eleven"; break; } case 12: { $output .= "&amount/twelve"; break; } case 13: { $output .= "&amount/thir"."&amount/teen"; break; } case 14: { $output .= "&amount/four"."&amount/teen"; break; } case 15: { $output .= "&amount/fif"."&amount/teen"; break; } case 16: { $output .= "&amount/six"."&amount/teen"; break; } case 17: { $output .= "&amount/seven"."&amount/teen"; break; } case 18: { $output .= "&amount/eight"."&amount/teen"; break; } case 19: { $output .= "&amount/nine"."&amount/teen"; break; } } if ($divident == 100000) { $output .= "&amount/thousand"; } $amount = (int)substr($amount, 1, strlen($amount)); $divident = ($divident / 10); break; } case 20: { $output .= "&amount/twenty"; break; } case 30: { $output .= "&amount/thirty"; break; } case 40: { $output .= "&amount/fourty"; break; } case 50: { $output .= "&amount/fifty"; break; } case 60: { $output .= "&amount/sixty"; break; } case 70: { $output .= "&amount/seventy"; break; } case 80: { $output .= "&amount/eighty"; break; } case 90: { $output .= "&amount/ninety"; break; } } if ($tmpAmount2 >= 10) { $amount = (int)substr($amount, 1, strlen($amount)); if (($amount>1000) && (($tmpAmount2%10) == 0)) { $output .= "&amount/thousand"; $divident = ($divident / 100); } else { $divident = ($divident / 10); } } else { $amount = (int)substr($amount, 2, strlen($amount)); $divident = ($divident / 100); } break; } case 1000: { $output .= "&amount/thousand"; break; } } } $amount = (int)substr($amount, 1, strlen($amount)); $divident = ($divident / 10); } echo $output; ?>
based on qbD4G
Output for 4.3.0 - 7.2.0
amount/nine&amount/hundred&amount/and&amount/twenty&amount/thousand&amount/nine&amount/hundred&amount/and&amount/fif&amount/teen