我的字符串看起来像这样:
$str = "How are you doing?";
如何将此字符串转换为如下所示的数组:
$arr = array("Ho","w ","ar","r ","yo","u ","do","in","g?");
答案 0 :(得分:9)
$array = str_split($str, 2);
答案 1 :(得分:4)
答案 2 :(得分:2)
看看str_split();它允许您按可定义的字符数拆分字符串,因此您的代码将如下所示:
$arr = str_split($str, 2);
将$str
拆分为数组$arr
,其中每个元素包含两个字符,