title: Passing an array from php to js
body: <p>I've file with extension php. In here I've read information from Database. And I need to pass this data(associate array) to js, which also include in this php file.</p>
  
  <pre><code>&lt;?php
      require('../db.php');
  
      function var_dump1($arr) {
          echo '&lt;pre&gt;';
          var_dump($arr);
          echo '&lt;/pre&gt;';
      }
  
      // load data from Database
      $query = R::getAll("SELECT * from questions");
      var_dump1($query);
  
  ?&gt;
  
  &lt;script&gt;
  const arr = JSON.parse( '&lt;?php echo json_encode($query); ?&gt;' );
  console.log(arr);
  
  &lt;/script&gt;   
  </code></pre>
  
  <p>Outputs:</p>
  
  <blockquote>
    <p>var_dump1($query);</p>
  </blockquote>
  
  <pre><code>array(5) {
    [0]=&gt;
    array(7) {
      ["id"]=&gt;
      string(1) "1"
      ["question"]=&gt;
      string(143) "The ______________ of a table is used to modify the design of a table, like modifying the name of a field or changing the data type of a field."
      ["answer1"]=&gt;
      string(14) "Datasheet View"
      ["answer2"]=&gt;
      string(11) "Desisn View"
      ["answer3"]=&gt;
      string(10) "Table View"
      ["answer4"]=&gt;
      string(11) "Wizard View"
      ["true_answer"]=&gt;
      string(1) "1"
    }
    [1]=&gt;
    array(7) {
      ["id"]=&gt;
      string(1) "2"
      ["question"]=&gt;
      string(83) "You can select multiple fields of a table in design view by using the ________ key."
      ["answer1"]=&gt;
      string(3) "Alt"
      ["answer2"]=&gt;
      string(8) "Spacebar"
      ["answer3"]=&gt;
      string(5) "Shift"
      ["answer4"]=&gt;
      string(4) "Ctrl"
      ["true_answer"]=&gt;
      string(1) "3"
    }
  ...
  </code></pre>
  
  <blockquote>
    <p>console.log(arr);</p>
  </blockquote>
  
  <pre><code>Uncaught SyntaxError: missing ) after argument list
  </code></pre>
  
  <p>Conclusion:
  On the part of php all good. But when we try to parse this array in js object in js part - We see strange Error.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>How to load data(For example, associate array, in my case) from php to js. When php and js are in the same extension file(php).</li>
  <li><ol>
  <li>How to load data(For example, associate array, in my case) from php to js. When php and js are in different files. For example We've 1 extension file php, where we've implement logic(With DB, in my case). And we need to import this data to extension file js.</li>
  </ol></li>
  </ol>