Making Javascript array with PHP
576
Solution:
You can use this
// declare an array
$json_array = array();
while ($row2 = mysqli_fetch_array($result2)) {
// add this code
$json_array[] = array(
"{$row2['Straat']}",
"{$row2['Noorderbreedte']}",
"{$row2['Westerlengte']}",
$row2['ID']
);
//echo '[' . $row2['Straat'] . ',' . $row2['Noorderbreedte'] . ',' . $row2['Westerlengte'] . ',' . $row2['ID'] . '],';
}
?>
<script type="text/javascript">
var locations = <?php echo json_encode($json_array);?>
Answer
Solution:
There's no need to invent a wheel.
json_encode
function will do what you need:PHP:
JS: