I'm trying to pass an array from php to JavaScript. But in js the array values are being read as each individual char. My code;
<?php
$arr=array(1=>'apple', 2=>'ball');
$garr=json_encode($arr);
?>
<script>
var ax = '<?php echo $garr; ?>';
alert(ax.length);
for(var n=0;n<ax.length; n++)alert(ax[n]);
</script>
The result is lenght=23 and each char as output.
Thank you for your help.