How can you structure a PHP while loop to display a header, a for loop, and a footer within the loop?
To structure a PHP while loop to display a header, a for loop, and a footer within the loop, you can include the header before the while loop, the footer after the while loop, and place the for loop inside the while loop. This way, the header will be displayed only once at the beginning, the for loop will iterate through its content, and the footer will be displayed only once at the end.
<?php
// Display header
echo "<h1>Header</h1>";
// Initialize while loop
$counter = 0;
while ($counter < 3) {
// Display for loop content
for ($i = 1; $i <= 5; $i++) {
echo "For loop iteration $i <br>";
}
$counter++;
}
// Display footer
echo "<h1>Footer</h1>";
?>