Skip to content

Instantly share code, notes, and snippets.

@arbaaz
Created February 12, 2014 18:23
Show Gist options
  • Save arbaaz/8961526 to your computer and use it in GitHub Desktop.
Save arbaaz/8961526 to your computer and use it in GitHub Desktop.
passing variable to javascript
passing a php variable to the javascript
<?php
$phpdata=array('key1'=>'some value','key2'=>'another value');
$jsondata=json_encode($phpdata);
echo "var mydata=".$jsondata.";";
?>
This will give you javascript that looks like this:
var mydata={'key1':'some value','key2':'another value'};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment