Hello I am having some trouble when it comes to iterating through my array chunks.
I am trying to put together an image gallery in which sets of 3 images follow a pattern then the next set of three follow the opposite of the pattern. I am pretty sure I am close, but I can not quite seem to figure out how exactly to select either the 1st, 2nd, 3rd, etc. chunk of my array with a for loop.
This is a print_r of my sample set.
Array (
[0] => Array ( [0] => images/uploads/cardinal.png [1] => images/uploads/fb.png [2] => images/uploads/logo.png )
[1] => Array ( [0] => images/uploads/masc.png [1] => images/uploads/sportclubslogo.png [2] => images/uploads/venue.jpg )
)
I then have the two patterns which print out three images in a certain pattern, the problem is I am unsure how to loops through my chunks and select the evens to follow pattern1 and the odds to follow pattern2. Below is the code I am currently using to attempt this:
foreach($chunks as $chunk) {
print_r($chunk);
if($chunks % 2 == 0){
echo "<div class='row'>
<div class='gal-img medium-8 large-8 columns'>";
echo "<img src='".$chunk[0]."' alt='gallery1'/>";
echo "</div>
<div class='gal-img medium-4 large-4 columns'>";
echo "<img src='".$chunk[1]."' alt='gallery2'/>";
echo "<img src='".$chunk[2]."' alt='gallery3'/>";
echo "</div>
</div>";
}
else {
echo "<div class='row'>
<div class='gal-img medium-4 large-4 columns'>";
echo "<img src='".$chunk[0]."' alt='gallery4'/>";
echo "<img src='".$chunk[1]."' alt='gallery5'/>";
echo "</div>
<div class='gal-img medium-8 large-8 columns'>";
echo "<img src='".$chunk[2]."' alt='gallery6'/>";
echo "</div>
</div>";
}
}
I am still planning on refactoring the foreach loop, I just want to see it working before I write the two functions. The final output I am trying to achieve looks similar to this:
| || small |
| Large || small |
| small || |
| small || Large |
Thanks in advance
chunk[index]as opposed to usingchunks[index]$key % 2 == 0something