I’m trying to sort everything out using array & loops
lets say this is an array,
$arr = array('One','Two','Three','Four','Five','Six');
i want to select first three of them to be used as
$arr[0], $arr[1] and $arr[2]
this ends up with one,two,three
i want to use the same for next 3..
something to break it and use the same 0 1 2 index again to return second three
here’s an example to explain more,
$arr = array('One','Two','Three','Four','Five','Six');
echo $arr[0].$arr[1].$arr[2]; // OneTwoThree
break; // < ??
echo $arr[0].$arr[1].$arr[2]; // FourFiveSix
also, i want to use it with foreach loop
$arr = array('One','Two','Three','Four','Five','Six');
foreach($arr as $num){
echo $num; // OneTwoThree
if($something == 3){ // < ??
break; // < ??
}
echo $num; // FourFiveSix
}
and what im trying to do is using each three arrays of the array to use them later
Use array_chunk and loop over the result:
Here it is with added linebreaks:
Note: The last element may have less than three elements! A possible fix for this is to use implode to concatenate the elements: