我有一个字符串,它使用空格作为分隔符分解成一个数组。例如,是否可以将前 4 个单词分解为数组,将其余单词分解为 ONE 数组元素?
截至目前,代码是这样的
$string = 'This is a string that needs to be split into elements';
$splitarray = explode(' ',$string);
这给出了一个数组
Array
(
[0] => This
[1] => is
[2] => a
[3] => string
[4] => that
[5] => needs
[6] => to
[7] => be
[8] => split
[9] => into
[10] => elements
)
我需要的是让数组看起来像这样
Array
(
[0] => This
[1] => is
[2] => a
[3] => string
[4] => that
[5] => needs
[6] => to be split into elements
)
这样的事情可能吗?