Home javascript How to transfer an array of PHP to JavaScript

How to transfer an array of PHP to JavaScript

Author

Date

Category

received an array from the database. You need to process it in JavaScript. Help)

& lt;? php
  $ ID1 = Array ("id" = & gt; "1", "name" = & gt; "block");
  $ json = json_encode ($ ID1);
? & gt;
& lt; script & gt;
  var id1 = json.parse (& lt;? php echo $ json;? & gt;);
& lt; / script & gt;
// What am I doing wrong to use JSON format?

Answer 1, Authority 100%

as an option Try to wrap the output in quotes;

& lt; script & gt;
  var id1 = json.parse ('& lt; php echo $ json;? & gt;);
& lt; / script & gt;

Answer 2

And as an option is just purely with Masiva

var id1 = & lt;? PHP Print_R ($ ARR); ? & gt ;;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions