Why is my Javascript array empty? In a while loop I fill a variable ($btext). When I echo $btext everything is shown fine:
But if I try to fill the Javascript array nothing is printed there.
This is how I fill the variable $btext in php:
$btext .= "\"".${'name_'.$user}."\",";
Here the Javascript part:
var battletext = new Array(<? echo $btext; ?>);
If I define $btext like:
$btext = "\"Hallo\", \"Welt\"";
the Sourcecode looks like this:
<script>
var battletext = new Array("Hallo", "Welt");
</script>
$btext = array(); $btext[] = ${'name_'.$user}; echo "var battletext = ".json_encode($btext).";";
– DaveRandom May 24 '12 at 11:11