Jump to content

Archived

This topic is now archived and is closed to further replies.

ssjskipp

explode() help

Recommended Posts

Okay, is there a way to explode, say:
$a = "test";
into an array of:
$array = ["t", "e", "s", "t"]

EDIT:

Nevermind, I got it:
"$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);"

Share this post


Link to post
Share on other sites
str_split would be a bit faster.

Share this post


Link to post
Share on other sites
[!--quoteo(post=373653:date=May 14 2006, 12:43 AM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 14 2006, 12:43 AM) [snapback]373653[/snapback][/div][div class=\'quotemain\'][!--quotec--]
str_split would be a bit faster.
[/quote]
it's plenty fast for what I need.

Share this post


Link to post
Share on other sites
You can treat a string as an array of characters

[code]$a = 'test';

for ($i=0; $i < 4; $i++)
{
         echo $a{$i} . '<br>';
}[/code]

-->
[code]t
e
s
t[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.