This question already has an answer here:
- Output php data into jquery array? 2 answers
I've got a problem to pass a var from php to js. BUT, I've already read all the related topics without finding any clue... I've got a js script, which contains the part
data: [
{ dt: '2009', value: 10 },
{ dt: '<?= $vstDate[0] ?>', value: 20 },
{ dt: '2009', value: 10 },
],
Then, what I'd like to do is adding a given number of vars, stored in a php array. I tried this, without getting it to work :
data: [
<?php
for($i=0; $i<=count($vststats)-1; $i+=1) {
echo json_encode("{ dt: ".$vststats[$i].", value: 5 },");
}
?>
],
Please, how could I make it working ? All my thanks in advance !
</div>