Solution 1:
PHP’s alternative syntax is convenient for mixing loops with HTML, making templates easier to read:
<?php for ($floorNow = 1; $floorNow <= 5; $floorNow++) :
$floorDiv = 'floorData' . $floorNow;
?>
<div class="FloorH">
First Floor
<button value="<?= htmlspecialchars($floorDiv) ?>"
onclick="changeBG(this.value, '#F0F')">
Magenta
</button>
</div>
<div id="<?= $floorDiv ?>"></div>
<?php endfor; ?>
Explanation:
for (…): … endfor; is the alternative syntax for loops, ideal for HTML templates.
$floorDiv dynamically generates unique IDs for each floor.
htmlspecialchars() ensures the ID is safe to use in HTML attributes.
Each button calls changeBG() with the corresponding floor ID and a color.
✅ This syntax keeps your PHP and HTML clean and readable.