0

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 !

1

1 Answer 1

0

First make an array in php and in end pass array to JSON_ENCODE

//Array
$temp = array(array('dt'=>2009,'value'=>10), array('dt'=>2010,'value'=>10))

//json encode
echo json_encode($temp);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.