Search code examples
phparrayssplit

Split string into an array of characters


How can I convert a string to an array? For instance, I have this string:

$str = 'abcdef';

And I want to get:

array(6) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  string(1) "d"
  [4]=>
  string(1) "e"
  [5]=>
  string(1) "f"
}

Solution

  • Use str_split http://www.php.net/manual/en/function.str-split.php