Created
February 12, 2014 18:23
-
-
Save arbaaz/8961526 to your computer and use it in GitHub Desktop.
passing variable to javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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