I have a multidimensional array that I want to break into 6 div columns, and I can't seem to do it so any help with this ?
Here's the array :
Array
(
[0] => Array
(
[id] => 17
[title] => White
[ref] => 24941
)
[1] => Array
(
[id] => 18
[title] => Blue
[ref] => 11395
)
[2] => Array
(
[id] => 19
[title] => Red
[ref] => 11394
)
.
.
.
and here's my foreach loop
:
echo '<div class="row">';
echo '<div class="col-xs-2">';
$i = 1;
foreach ($colors as $key => $value) {
if ($i % 6 === 0) {
echo $value['title']. 'Ref: '. $value['ref']
}
echo '</div><div class="col-xs-2">';
$i++;
}
echo '</div>';
echo '</div>';
Much appreciated.
Though I don't get what you do with $all_colors = explode(",",$check_colors['value']);
, this should help you out:
$item = reset($colors);
while ($item) {
echo "<div class='row'>";
for ($i = 0; $i < 6; $i++) {
if ($item)
echo "<div class='col-xs-2'>{$item['title']}Ref: {$item['ref']}</div>";
else
break;
$item = next($colors);
}
echo "</div>";
}