title: Printing PHP variables into JavaScript variables
body: <p>Yes I know this question gets asked a lot, but I'm fairly new to JS and I need to use a php variable in some JS. I'm more then aware that PHP is executed server side and JS is client side however other people claim that this works.</p>
  
  <p>I've got a PHP variable called "test1" that I want to log to the JS console (for instance):</p>
  
  <pre><code> &lt;?php
   $test1 = '1';
  
   print '
   &lt;script type="text/javascript"&gt;
        var carnr;        
        carnr = "&lt;?php print($test1); ?&gt;"
        console.log(carnr);
   &lt;/script&gt;';
   ?&gt;
  </code></pre>
  
  <p>What this does is print " " to the JS console. Not exactly what I was hoping for. </p>
  
  <p>Now this may not even be doable and I may have to pass the variable off the page and back in again with AJAX, but I'd rather have a quick and easy solution if there is one available!</p>
  
  <p>Any help is appreciated.</p>