I am trying to assign a PHP array into a javascript variable like this:
var jsArray = <?php echo $phpArray; ?>;
But it doesn't work.
What am I doing wrong?
You should try to use JSON
var jsArray = <?php echo json_encode($phpArray); ?>;
accessible then via
jsArray.someKey
demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With