-2

I have an array which have some values stored in it but I want to transfer the elements of that array into javascript array for further processing. How can I do so?

1 Answers1

2

You can encode your variable to json using json_encode($php_array). Then on JavaScript side, parse it back using JSON.parse()

<script>
    var foo = <?php echo json_encode($array); ?>;
</script>
Alexandre Tranchant
  • 4,426
  • 4
  • 43
  • 70