born2hack
born2hack

Reputation: 255

PHP arrays - simple query

Ok I know this is simple, in fact damn simple, I did this in the last project about a week ago, but I don't know why it has skipped off my head.

Input:

$word = "stack";

What I want to do is:

$array = array("s", "t", "a", "c", "k");

Any help will be appreciated!

Upvotes: 1

Views: 118

Answers (3)

Omry Yadan
Omry Yadan

Reputation: 33646

Try this:

var_dump(str_split("abc"));

Upvotes: 0

NSSec
NSSec

Reputation: 4551

Your question isn't too clear, but I suspect you want to turn your string into an array. You don't have to, actually. You can just access $word as if it were an array:

$word = 'stack';
for ($i=0, $m = strlen($word); $i < $m; $i++)
    echo $word[$i], "\n";

Upvotes: 3

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179119

str_split();

Upvotes: 2

Related Questions