How can Bootstrap grids be effectively utilized in PHP to display content in rows and columns?

To effectively utilize Bootstrap grids in PHP to display content in rows and columns, you can use PHP to dynamically generate the HTML structure with the appropriate Bootstrap grid classes. This allows you to easily create responsive layouts that adapt to different screen sizes.

<?php
// Define an array of content to display
$content = array(
    "Content 1",
    "Content 2",
    "Content 3",
    "Content 4",
    "Content 5"
);

// Define the number of columns per row
$cols_per_row = 2;

// Loop through the content and generate the HTML structure with Bootstrap grid classes
echo '<div class="container">';
for ($i = 0; $i < count($content); $i++) {
    if ($i % $cols_per_row == 0) {
        echo '<div class="row">';
    }
    echo '<div class="col-md-' . (12 / $cols_per_row) . '">' . $content[$i] . '</div>';
    if ($i % $cols_per_row == $cols_per_row - 1 || $i == count($content) - 1) {
        echo '</div>';
    }
}
echo '</div>';
?>