I\'m trying to create a common constants file to share between php and javascript, using JSON to store the constants. But I\'m wondering why pass the JSON from PHP to javasc
json_encode
is a function that converts a PHP array into a JSON string, and nothing more. Since your $json_obj
variable is already a JSON string, no further conversion is needed and you can simply echo it out.
To get to your $json_obj
string from an array your code would have looked like this
$json_array = array(
"const1" => "val",
"const2" => "val2"
);
$json_obj = json_encode($json_array);