How do I explode an integer

chriscandy picture chriscandy · Feb 1, 2011 · Viewed 52.2k times · Source

the answer to this could be easy. But I'm very fresh to programming. So be gentle...

I'm at work trying to do a quick fix for one of your customers. I want to get the total numbers of digits in a integer, and then explode the integer:

rx_freq = 1331000000 ( = 10 )
  $array[0] = 1
  $array[1] = 3
  .
  .
  $array[9] = 0

rx_freq = 990909099 ( = 9 )
  $array[0] = 9
  $array[1] = 9
  .
  .
  $array[8] = 9

I'm not able to use explode, as this function need a delimiter. I've searched the eyh'old Google and Stackoverflow.

Basically: How do I explode an integer without delimiter, and how do I find the number of digits in an integer.

Answer

mfonda picture mfonda · Feb 1, 2011

$array = str_split($int) and $num_digits = strlen($int) should work just fine.