0

I'm trying to pass a php array into Javascript, this is what I have

var urls = <?php echo $json_array[0]; ?>;

However JS seems to have issues with the bracket. Maybe I'm not approaching this correctly but i know if I could get the same $json_array[0] spits out in php into my js I would be all set.

Ryan Litwiller
  • 497
  • 5
  • 24
  • *"However JS seems to have issues with the bracket."* The browser doesn't even see the `[]` since PHP runs on the server side. – Felix Kling Feb 09 '16 at 05:34

1 Answers1

0

If $json_array[0] contains a String, You are probably missing quotes:

var urls = '<?php echo $json_array[0]; ?>';
Vicky Gonsalves
  • 11,593
  • 2
  • 37
  • 58