Hello I'm trying to create multiple markers on a leaflet map using a for loop in the scriptsection of a phtml page. I want to display this map on multiple pages however each page should show different markers. For this I pass a list of identifiers in the php section of the phtml file. Now I want to loop through this list and call another php array (all in the same file) with the for loop val.
e.g.
<?php
$buidling_code = $block->getData('building_code');
$building_array = [];
if (strpos($buidling_code, '|') !== false) {
$building_array = explode("|",$building_code);
}else{
array_push($building_array,$buidling_code);
}
?>
so here we could have 5 building codes these codes would then need to be used in the following script part
<script>
for(i = 0; i<<?=count($building_array)?>;i++)
var marker = L.marker([<?=$location_data[$building_array[$i]]['cordinates'][0]?>, <?=$location_data[$buidling_code]['cordinates'][1]?>]).addTo(mymap).bindPopup("<b><a href=<?=$location_data[$buidling_code]['popup']?>><?=$location_data[$buidling_code]['name']?></a></b>.");
}
But this fails is there a way to use the i value in the php part in the script section?