This question already has an answer here:
I am trying to dynamically create variables in javascript
. In my PHP
code I already dynamically create variables from SQL
output which gives me $res1
, $res2
, etc. Now I want to use these in my javascript
but of course I cannot hardcode it for I can never know how many of the $res
variables the PHP
will generate.
I have the feeling I am already fairly close though. I have the following:
var i=1;
while (i<=count) {
var name = "<?php ${"res".$_GET['i']} ?>";
}
</div>