php foreach wrap every 2 divs

后端 未结 2 420
梦毁少年i
梦毁少年i 2021-01-27 11:10

I need to wrap every 2 divs with another div for a project (a row) so it will look like:

Item
2条回答
  •  逝去的感伤
    2021-01-27 11:58

    You should open and close your in the books loop, and add a late check for odd books:

    ";
            }
            $book_name      = $book['tag_name'];
            $book_name_trim = str_replace(' ', '-', $book_name);
            ?>
            
            

    "; $count = 0; } } } if ($count > 0) { echo "
    "; } ?>

Doing so, your $count variable will be incremented only when foreach($books AS $book) loop is run (thus you have at least one book to print)

提交回复
热议问题