开发者

Foreach loop in 3 coulm divs with nested divs in each column

开发者 https://www.devze.com 2023-02-13 04:14 出处:网络
Need some clues with the rest of this script: // Num of columns $col = 3; foreach ($schema as $key => $array) {

Need some clues with the rest of this script:

// Num of columns
$col = 3;
foreach ($schema as $key => $array) {

// wrapper div
if($key % $col == 0) {
    echo '<div class="wrapper" style="float: left;">;
}

// divs inside columns  
foreach ($array as $c => $value) {
    echo '<div开发者_如何学Python>' . $value . '</div>';
}

// Here I need to close wrapper div
// @ to do
}


// Num of columns
$col = 3;
echo '<div class="wrapper" style="float: left;">';
$count = 1;

foreach ($schema as $key => $array) {

    // wrapper div
    if($count % $col == 0) {
       echo '</div>';

       if(isset($schema[$key+1]))   // check if next element exists then start new div
           echo '<div class="wrapper" style="float: left;">';
   }

   // divs inside columns  
   foreach ($array as $c => $value) {
       echo '<div>' . $value . '</div>';
   }

   $count++;
}

if(count($schema) % $col != 0)
   echo '</div>'; // at last close div
0

精彩评论

暂无评论...
验证码 换一张
取 消