How to autocut cells after a specific number have been made and start a new row

后端 未结 1 714
走了就别回头了
走了就别回头了 2021-01-17 02:40

I have a json file with an array of over 100 images

foreach($images as $image)
    {
                  $imagelink = $image[\'link\'];
                  echo          


        
相关标签:
1条回答
  • 2021-01-17 03:24

    How about this:

    echo "<table>";
    
    $col = 0;
    $maxCols = 4;
    foreach($images as $image)
    {
        // first row, or we've already output the max number of images per row so start a new one
        if( $col % $maxCols == 0 ) {
            // we need to end a previously started row
            if( $col != 0 ) {
                echo "</tr>";
            }
    
            echo "<tr>";
        }
    
        $imagelink = $image['link'];
        echo "<td><img src=$imagelink></td>";
    
        $col++;
    }
    
    // we didn't end the last row we started
    if( $col != 0 ) echo "</tr>";
    
    echo "</table>";
    
    0 讨论(0)
提交回复
热议问题