PHP: Split string into array, like explode with no delimiter PHP: Split string into array, like explode with no delimiter arrays arrays

PHP: Split string into array, like explode with no delimiter


$array = str_split("0123456789bcdfghjkmnpqrstvwxyz");

str_split takes an optional 2nd param, the chunk length (default 1), so you can do things like:

$array = str_split("aabbccdd", 2);// $array[0] = aa// $array[1] = bb// $array[2] = cc  etc ...

You can also get at parts of your string by treating it as an array:

$string = "hello";echo $string[1];// outputs "e"


What are you trying to accomplish? You can access characters in a string just like an array:

$s = 'abcd';echo $s[0];

prints 'a'


Try this:

$str = '123456789';$char_array = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);