php read json data code example
Example 1: json php
$person = array(
"name" => "KINGASV",
"title" => "CTO"
);
$personJSON=json_encode($person);
$personJSON = '{"name":"KINGASV","title":"CTO"}';
$person = json_decode($personJSON);
echo $person->name;
Example 2: php json_decode
$personJSON = '{"name":"Johny Carson","title":"CTO"}';
$person = json_decode($personJSON);
echo $person->name;
Example 3: php decode json file
$json = json_decode(file_get_contents('/path/to/your/file.json'));
Example 4: php return json
header('Content-type: application/json');
echo json_encode($array);
Example 5: parse json phph
echo json_decode("[1,2,3]")[0];
Example 6: return json in php
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);