str_split() 将字符串分割为一个数组,成功返回一个数组。
语法:
array str_split( string string [, int length] )
参数 | 说明 |
---|---|
string | 需要分割的字符串 |
length | 可选,表示每个分割单位的长度,不可小于1 |
例子:
<?php $str = 'one two three'; $arr1 = str_split($str); $arr2 = str_split($str, 3); print_r($arr1); print_r($arr2); ?>
输出结果如下:
Array ( [0] => o [1] => n [2] => e [3] => [4] => t [5] => w [6] => o [7] => [8] => t [9] => h [10] => r [11] => e [12] => e ) Array ( [0] => one [1] => tw [2] => o t [3] => hre [4] => e )