JSON encode PHP

PHP has some built-in functions to handle JSON. Objects in PHP can be converted into JSON by using the PHP function json_encode():

PHP file

<?php
$data->name = "John";
$data->age = 30;
$data->city = "New York";

echo $json_data = json_encode($data);

?>

Result:

{"name":"John","age":30,"city":"New York"}

JSON Array PHP

$age = array("Peter"=>35, "Ben"=>37, "Joe"=>43);

echo json_encode($age);

Result:

{"Peter":35,"Ben":37,"Joe":43}
READ :  Backup Remote VPS Linux Cronjob Automatis