Page 1 of 1

[solved] - number string to array question

Posted: Tue Aug 23, 2005 10:13 am
by reverend_ink
I need to take a number string and convert it to an array, e.g. 1234 to $array[0] = 1 etc.

I know how to take 123, 124, 125 to an array but unable to find how to take a single string and explode that into an array.

Your help is appreciated.

:)

Posted: Tue Aug 23, 2005 10:33 am
by JayBird
Sorry, the previous funtion was PHP5 only...keep forgetting to check these thing. Anyway, this will work

Code: Select all

$string = "123456";

$array = explode("\1\2\3",chunk_split($string, 1, "\1\2\3"));

print_r($array);

// Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => )