我有一个字符串,它使用空格作为分隔符分解到一个数组中。例如,是否有可能将前4个单词分解为数组,其余单元分解为1个数组元素?PHP将字符串的第一部分分解为数组元素,将第二部分分解为一个元素
为现在的代码是这样的
$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
)
是什么这可能吗?
阅读手册,['爆炸()'](http://php.net/manual/en/function.explode .php)有第三个选项:'数组explode(字符串$ delimiter,字符串$ string [,** int $ limit **])':) – HamZa
当然是极限!谢谢:) –