I have a php array:
$x = array("1","2","3");
I also have javascript code to convert the php array into a javascript array:
var x = <?php echo json_encode($x) ?>;
It works perfectly when I type this out in the index.php file (ie - I can use that array in any other javascript file):
<script type="text/javascript"> var x = <?php echo json_encode($x) ?>; </script>
But it doesn't work when I do this:
<script type="text/javascript" src="file.js"></script>
And file.js contains:
var x = <?php echo json_encode($x) ?>;
I just can't understand why this is the case, any idea why? Thanks in advance.