[solved] - number string to array question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

[solved] - number string to array question

Post 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.

:)
Last edited by reverend_ink on Tue Aug 23, 2005 10:33 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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] => )
Post Reply