Here is a short snippet to pass data from PHP to JavaScript:

<?php
 $var = "foo";

 $output = "<script>";
 $output .= "var jsVar = '" . $var . "';";
 $output .= "alert(jsVar);";
 $output .= "</script>";

 echo $output;
?>

If you liked this, please share this on Facebook, Twitter or Google+.