Search code examples
phpsplit

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.


Solution

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