The json_encode() is a function of PHP. It is used to transform the associative array of PHP into JSON data (Javascript object notation).
Create an associative array to change it into JSON data. Here I have created an array which is:-
$assoc_array = array("name"=>"Jaischool","city"=>"Sikar","state"=>"RJ","country"=>"India");
To transform $assoc_array into JSON data, use json_encode() function and give associative array name in its parenthesis.
$json_data = json_encode($assoc_array);
Now print it with print_r() function. Or you can also print it by an echo.
echo $json_data;
json_encode() function's code example
<?php
$assoc_array=array("name"=>"Jaischool","city"=>"Sikar","state"=>"RJ","country"=>"India");
$json_data = json_encode($assoc_array);
echo $json_data
?>
Publish A Comment