$arr = json_decode($json, true);
// Loop through the associative array
foreach($arr as $key=>$value){
echo $key . " => " . $value . "<br>";
}
header('Content-type: application/json');
echo json_encode($array);
//e.g your JSON Req is like this {"UserName":"Ranish","Password":"asdasdasd"}
$jsonReqUrl = "php://input";
$reqjson = file_get_contents($jsonReqUrl);
$reqjsonDecode = json_decode($reqjson, true);
echo $reqjsonDecode['UserName'];
<?php
$jsonurl = "https://reqres.in/api/users/2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
echo $jsonDecode['data']['email'];
?>
<?php
$jsonurl = "https://reqres.in/api/users?page=2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
var_dump($jsonDecode['data']);
foreach($jsonDecode['data'] as $mydata){
echo $mydata['email'] . "<br>";
}
?>
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
//In JS File
//JQUERY AJAX
$.ajax({
url: "path/to_php_file.php",
dataType: "json",
type: "GET",
data: {datax : datax },
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);