convert response to json php code example
Example 1: php response json
<?PHP
$data = ;
header('Content-Type: application/json');
echo json_encode($data);
Example 2: php json_decode
$personJSON = '{"name":"Johny Carson","title":"CTO"}';
$person = json_decode($personJSON);
echo $person->name;
Example 3: php json encode
$person = array(
"name" => "Johny Carson",
"title" => "CTO"
);
$personJSON=json_encode($person);
Example 4: return json in php
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);