What is the best practice for dynamically creating page breaks in a PHP project, such as in a small shop application?

When dynamically creating page breaks in a PHP project, such as in a small shop application, it is best to use CSS to control the layout and styling of the page breaks. By applying CSS styles to elements on the page, you can ensure that content is properly divided across multiple pages when printed or viewed in a paginated format.

// Example PHP code snippet for dynamically creating page breaks using CSS

echo '<style>
@media print {
    .page-break { page-break-after: always; }
}
</style>';

// Loop through items to display on the page
foreach ($items as $item) {
    echo '<div class="item">' . $item['name'] . '</div>';
    
    // Insert a page break after every 5 items
    if ($item['id'] % 5 == 0) {
        echo '<div class="page-break"></div>';
    }
}