title: How to access PHP variable in JavaScript code?
body: <p>I have a variable in PHP code which I want to access in my JavaScript function. Below is my code.</p>
  
  <p><strong>myfile.php</strong></p>
  
  <pre><code>&lt;?php
    $i = 0;
  ?&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript"&gt;
        function SetText() {
          //I want to access value of i here
          //alert(i);
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;button type="button" id="mybutton" onclick="SetText()"&gt;Click ME&lt;/button&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>What are the ways to access I variable declared in php code in the JavaScript code?</p>