[thelist] PHP, 8 digit string, to 8 item array..
Matt Warden
mwarden at gmail.com
Tue Jan 16 14:30:10 CST 2007
On 1/16/07, Tris <beertastic at gmail.com> wrote:
> I wanna take an Int (eg: 48392034)
> and make an array:
> $myArray[0] = 4;
> $myArray[1] = 8;
> $myArray[2] = 3;
> $myArray[3] = 9;
> $myArray[4] = 2;
> $myArray[5] = 0;
> $myArray[6] = 3;
> $myArray[7] = 4;
>
> I've looked at substr, ut it doesn't relal yhelp, as there's no
> characters to split by..
> what am I missing?
In PHP, strings are already arrays. I learned this from this list a
little over a year ago, when I supplied a solution to a problem posed
here by another:
http://mwarden.f2o.org/sandbox/viewsource.php?linemode=0&f=interleaveStrings.php
Specifically:
$a = preg_split('//', $a, -1, PREG_SPLIT_NO_EMPTY);
This does what you are looking to do, except that $a is effectively
already an array. Instead of looping through the converted array and
doing $a[$i], I could have instead done: $a{$i} in the original
string.
--
Matt Warden
Cleveland, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the thelist
mailing list