我有以下字符串:
$my_string = 'one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen';
我想将$my_string
转换为块数为4的数组,如下所示:
$my_array = Array (
array(
"one",
"two",
"three",
"four"
),
Array (
"five",
"six",
"seven",
"eight"
),
Array (
"nine",
"ten",
"eleven",
"twelve"
),
Array (
"thirteen",
"fourteen",
"fifteen"
)
怎么做?
我认为可以使用preg_split()功能完成吗?但我不知道该怎么做。
答案 0 :(得分:0)
一行简单的代码......
$array = array_chunk(explode('|', $my_string), 4);