Print all the elements of the array, three in a wrapper. Tell me how best to implement, as long as I understand the shit. An array of $ images with the number of images (number N) is given. Need to get around it
Пример массива $images[0], $images[1], $images[n] $images[0] => $images[0]['popup'],$images[0]['src'] $images[1] => $images[1]['popup'],$images[1]['src'] $images[n] => $images[n]['popup'],$images[n]['src'] $imax=count($images); for ($i = 0 ; $i < $imax ; $i++) { print '<div class="item">'; $images[$i]['popup']; $i++;if($i==$imax){echo '</div>';break;} $images[$i]['popup']; $i++;if($i==$imax){echo '</div>';break;} $images[$i]['popup']; $i++;if($i==$imax){echo '</div>';break;} print '</div>'; } Option decisions taken from the comments -
$tmpArray = array_chunk($image,3); foreach($tmpArray as $_image) { echo '<div>'; foreach($_image as $_subImage) { echo $_subImage; } echo '</div>'; } and
function split_my($arr, $size) { foreach(array_chunk($arr, $size) as $val) { echo "<div>". implode("", array_map(function($value){ return "<span> ".$value." </span>"; }, $val)). "</div>"; } }