I have a an array like so:
$fruit = array('Apple', 'Orange', 'Banana');
I would like to combine the array with a separator similar to implode but without converting the result to a string.
So instead of
implode('.', $fruit); // 'Apple.Orange.Banana'
the result should be:
array('Apple', '.', 'Orange', '.', 'Banana');
This could probably be achieved with loops, however, I am looking for the best possible solution. Maybe there is a native function that can accomplish that which I do not know of? Thanks in advance!
Use
array_splice()with a reversedforloopRemember to remove
1fromcount($fruit)so we won't add another.at the end of the array