How can the PHP code be modified to add a <br> tag after every 10th data record instead of after each record?
To add a <br> tag after every 10th data record instead of after each record, we can introduce a counter variable that increments with each record. When the counter reaches 10, we add the <br> tag and reset the counter to 0. This way, the <br> tag will only be added after every 10th record.
<?php
$counter = 0;
foreach ($data_records as $record) {
// Output the data record here
$counter++;
if ($counter == 10) {
echo "<br>";
$counter = 0;
}
}
?>
Keywords
Related Questions
- What best practices can be followed to avoid errors related to missing requirements in PHP scripts?
- What is the "Year 2038 Problem" in PHP and how does it affect strtotime function on 64-bit systems?
- What are the best practices for incorporating multilingual support in PHP scripts for user interface elements like buttons?