<?php $images = array( array("image" => "http://example.com/image1.jpg", "description" => "Desc 1"), array("image" => "http://example.com/image2.jpg", "description" => "Desc 2"), array("image" => "http://example.com/image3.jpg", "description" => "Desc 3"), array("image" => "http://example.com/image4.jpg", "description" => "Desc 4") ); $imagesPerRow = 3; $numberOfRows = ceil(count($images) / $imagesPerRow); for ($row = 0; $row < $numberOfRows; $row++) { echo '<div class="row">' . PHP_EOL; $offset = $row * $imagesPerRow; $imagesInRow = array_slice($images, $offset, $imagesPerRow); $columnWidth = 24 / count($imagesInRow); foreach ($imagesInRow as $image) { echo ' <div class="col-md-' . $columnWidth . '">'; echo '<img src="' . $image['image'] .'" alt="' . $image['description'] .'">'; echo '</div>' . PHP_EOL; } echo '</div>' . PHP_EOL; }
You have javascript disabled. You will not be able to edit any code.