将多维数组分解为多列


Break an multidimentional array into multiple columns

我有一个多维数组,我想把它分解成6个div列,但我似乎做不到,所以有什么帮助吗?

这是阵列:

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
        )
.
.
.

这是我的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>';

非常感谢。

虽然我不知道你对$all_colors = explode(",",$check_colors['value']);做了什么,但这应该会帮助你:

$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>";
}