title: How do I pass variables and data from PHP to JavaScript?
body: <p>I have a variable in PHP, and I need its value in my JavaScript code. How can I get my variable from PHP to JavaScript?</p>
  <p>I have code that looks like this:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $val = $myService-&gt;getValue(); // Makes an API and database call
  </code></pre>
  <p>On the same page, I have JavaScript code that needs the value of the <code>$val</code> variable to be passed as a parameter:</p>
  <pre class="lang-js prettyprint-override"><code>&lt;script&gt;
      myPlugin.start($val); // I tried this, but it didn't work
      &lt;?php myPlugin.start($val); ?&gt; // This didn't work either
      myPlugin.start(&lt;?=$val?&gt;); // This works sometimes, but sometimes it fails
  &lt;/script&gt;
  </code></pre>