str_split
將字符串轉換為數組
str_split()
函數把字符串分割到數組中。
把字符串"Shanghai" 分割到數組中:
<?php print_r ( str_split ( "Shanghai" ) ) ; ?>
親自試一試
使用length參數:
<?php print_r ( str_split ( "Shanghai" , 3 ) ) ; ?>
親自試一試
str_split ( string , length )
參數 | 描述 |
---|---|
string | 必需。規定要分割的字符串。 |
length | 可選。規定每個數組元素的長度。默認是1。 |