I am trying to come up with an elegant way to convert a number to single digits. I will use these single digits to show a nice graphic image of the number. The number will be small in the start, such as 100, and then it will climb to 1 million and probably not much further than that but it could go further. Can anyone provide any different methods or if my method is terrible? Or even different logic for the concept would be cool.
Here is what I have so far:
$number = "12,345,689";
echo $number."<br><br/>";
$length = strlen($number);
$digits = array();
$i=1;
while($length >= $i){
array_push($digits,substr($number, -$i,1));
$i++;
}
$digits = array_reverse($digits);
print_r($digits);
// results in
Array
(
[0] => 1
[1] => 2
[2] => ,
[3] => 3
[4] => 4
[5] => 5
[6] => ,
[7] => 6
[8] => 8
[9] => 9
)