If you want to spell out the complete number you can make use of the PEAR
Numbers_Words class. This class has a toWords
() method that accepts a +ve
or a -ve
num and returns the spelled out string representation of the number.
If you want to convert the number to string digit wise, I am not aware of any lib function. But you can code one yourself easily..stereofrog gives a good way to do this in his answer.
<?php
$arr = array(
-12,
20
);
foreach($arr as $num) {
$nw = new Numbers_Words();
echo "$num = ". $nw->toWords($num)."\n";
}
?>
Output:
C:\>php a.php
-12 = minus twelve
20 = twenty