0

I have a string like '6554', and I would like to change this to an array, resembling the following:

Array([0] => 6, [1] => 5, [2] => 5, [3] => 4)

The problem is that I can not be certain of the length of the number and the number has nothing separating each digit. The number will not be negative or a float. Any ideas on how I could do this?

2

2 Answers 2

2

How about using preg_split

$data=preg_split('//', $number, -1, PREG_SPLIT_NO_EMPTY);
print_r($data);
Sign up to request clarification or add additional context in comments.

Comments

1

New way to do this

$str = '123456';
for($i=0 ; $i < strlen($str) ;$i++)
{
   $array[]=$str{$i};
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.