在PHP中,有以下几种方法可以将字符串拆分成数组:
$str = "apple,banana,orange"; $arr = explode(",", $str); print_r($arr);
$str = "hello"; $arr = str_split($str); print_r($arr);
输出:Array ( [0] => h [1] => e [2] => l [3] => l [4] => o )
$str = "apple1banana2orange3"; $arr = preg_split("/\d/", $str); print_r($arr);
输出:Array ( [0] => apple [1] => banana [2] => orange )
$str = "Hello world"; $arr = str_word_count($str, 1); print_r($arr);
输出:Array ( [0] => Hello [1] => world )
以上就是使用php将字符串拆分成数组的几种常见方法的详细内容,更多关于php将字符串拆分成数组的资料请关注插件窝其它相关文章!