I have a string which gets exploded into an array using the space as a delimiter. Is it possible to , for example explode the first 4 words into the array and the rest into ONE array element?
as of now the code is like this
$string = 'This is a string that needs to be split into elements';
$splitarray = explode(' ',$string);
This gives an array
Array
(
[0] => This
[1] => is
[2] => a
[3] => string
[4] => that
[5] => needs
[6] => to
[7] => be
[8] => split
[9] => into
[10] => elements
)
What i need is for the array to look like this
Array
(
[0] => This
[1] => is
[2] => a
[3] => string
[4] => that
[5] => needs
[6] => to be split into elements
)
Is something like this possible?
explode()has a third option:array explode ( string $delimiter , string $string [, **int $limit** ] ):)