Skip to content
PHP Logo

How can the code be modified to ensure that the week count resets to 1 after reaching week 6?

The issue can be solved by adding a conditional statement that resets the week count to 1 when it reaches week 6. This can be achieved by checking if the week count is equal to or greater than 6, and if so, setting it back to 1.

php
// Initialize week count
$week = 1;

// Loop through the weeks
for ($i = 1; $i <= 10; $i++) {
    // Perform actions for each week
    
    // Check if week count is 6 or more, then reset to 1
    if ($week >= 6) {
        $week = 1;
    } else {
        $week++;
    }
    
    echo "Week: $week\n";
}