Convert a String into an Array of Characters

前端 未结 7 1278
陌清茗
陌清茗 2020-11-29 08:05

In PHP, how do I convert:

$result = "abdcef";

into an array that\'s:

$result[0] = a;
$result[1] = b;
$result[2] = c;         


        
7条回答
  •  余生分开走
    2020-11-29 08:33

    You can use the str_split() function:

    $value = "abcdef";
    $array = str_split($value);
    

    If you wish to divide the string into array values of different amounts you can specify the second parameter:

    $array = str_split($value, 2);
    

    The above will split your string into an array in chunks of two.

提交回复
热议问题