Try this ( but this is not good way of optimizing), use this if order of elements is matter
$string1 = "apple, banana, grape";
$string2 = "red, yellow, black";
$string3 = "north, south, east";
$string4 = "april, may, june";
$piece1 = explode(",", $string1);
$piece2 = explode(",", $string2);
$piece3 = explode(",", $string3);
$piece4 = explode(",", $string4);
$i = 0;
foreach($piece1 as $element){
$resultArray[] = $element;
$resultArray[] = $piece2[$i];
$resultArray[] = $piece3[$i];
$resultArray[] = $piece4[$i];
$i++;
}
var_dump(implode(",", $resultArray));
Result:
string(75) "apple,red,north,april, banana, yellow, south, may, grape, black, east, june"
Edited. More shorter way:
$i = 0;
foreach($piece1 as $element){
$resultArray.= $element.",".$piece2[$i].",".$piece3[$i].",".$piece4[$i];
$i++;
}
var_dump( $resultArray);
Result will be the same