Sudantha
Sudantha

Reputation: 16224

Split a string into an array of individual characters

I need to convert a PHP $var to a array.

I did like this

$array = array();
$var = $array;

but this way the doesn't give the output as this

Array ( [0] => [1] => 9 [2] => 7 [3] => 11 [4] => 5 )

It gives the value like a normal variable, it prints 154515100.

Upvotes: -1

Views: 2453

Answers (3)

JAL
JAL

Reputation: 21563

What is the variable to begin with?

If it was an object, you could cast it to an array like

$var=(array)$var;

It sounds like you want to convert from a string or an integer to an array, though. Please provide more details.

Upvotes: 3

jbenet
jbenet

Reputation: 3060

It depends on what the variable is. If it is a string, do: $array = str_split($var);

Upvotes: 3

Bakudan
Bakudan

Reputation: 19492

You should define $var as array first

Upvotes: 1

Related Questions