Solution:1
PHP alternative syntax is much easier for HTML templating
<?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 ?>