Answered by : mobile-star
header('Content-type: application/json');
echo json_encode($array);
Source : | Last Update : Fri, 27 Mar 20
Answered by : code-grepper
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
Source : | Last Update : Wed, 06 Nov 19
Answered by : perfect-pigeon
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Source : https://stackoverflow.com/questions/18866571/receive-json-post-with-php | Last Update : Sun, 08 Nov 20
Answered by : david-cortesi
//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 },
Source : https://stackoverflow.com/questions/4064444/returning-json-from-a-php-script | Last Update : Wed, 02 Feb 22
Answered by : borma425
$json = '
{ "type": "donut", "name": "Cake"
}';
$yummy = json_decode($json);
echo $yummy->type; //donut
Source : https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php | Last Update : Tue, 19 Oct 21
Answered by : better-bison-7ur2i4n3weko
<?php
$data = '{ "name": "Aragorn", "race": "Human"
}';
$character = json_decode($data);
echo $character->name;
Source : https://www.taniarascia.com/how-to-use-json-data-with-php-or-javascript/ | Last Update : Thu, 27 Aug 20
Answered by : annoyed-armadillo-ik49ahzrg9e2
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
Source : | Last Update : Thu, 01 Oct 20
Answered by : ankur-prajapati
$json = '
{ "type": "donut", "name": "Cake", "toppings": [ { "id": "5002", "type": "Glazed" }, { "id": "5006", "type": "Chocolate with Sprinkles" }, { "id": "5004", "type": "Maple" } ]
}';
$yummy = json_decode($json);
print_r($yummy);
Source : https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php | Last Update : Tue, 15 Jun 21
Answered by : long-locust-6bchlrhsm70y
<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
Source : https://stackoverflow.com/questions/4064444/returning-json-from-a-php-script | Last Update : Thu, 25 Nov 21