在PHP中,可以使用以下方法將字符串轉(zhuǎn)換為數(shù)組:
$str = "apple,banana,orange";
$arr = explode(",", $str);
print_r($arr);
輸出:
Array
(
[0] => apple
[1] => banana
[2] => orange
)
$str = "hello";
$arr = str_split($str);
print_r($arr);
輸出:
Array
(
[0] => h
[1] => e
[2] => l
[3] => l
[4] => o
)
$str = "apple,banana,orange";
$arr = preg_split("/,/", $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
)
這些是將字符串轉(zhuǎn)換為數(shù)組的一些常用方法,根據(jù)具體的需求和字符串的結(jié)構(gòu),選擇合適的方法進(jìn)行轉(zhuǎn)換。