how to retrieve json data in php code example
Example 1: php return json
header('Content-type: application/json');
echo json_encode($array);
Example 2: how to receive json data in php
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Example 3: fetch value from json link in php
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'url_here');
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
echo $obj->access_token;
Example 4: how to get data from json array in php
$data = json_decode($json);
Example 5: return json in php
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);