First of all, here's the code I'm using
$json = file_get_contents('./releases.json');
$data = json_decode($json, TRUE);
$region = isset($_GET['region']) ? $_GET['region'] : null;
# if region is not null: ?region=8
if ($region) {
$region_filter = function($v) use ($region) {
// 8 == Worldwide
if ($v['region'] == $region || $v['region'] == 8) {
return true;
} else {
return false;
}
};
$data = array_filter($data['data'], $region_filter);
}
header('Content-Type: application/json');
echo json_encode(array('data' => $data));
As you can see I'm using array('data' => $data) to store my JSON objects ($data) in array named 'data', but all this do is create a parent object data that has all the other objects not an array, how can i fix this? Thank you very much!
releases.json example:
{
"last_update_on": "2017-12-30",
"data": [{..}, {..}]
}
echo json_encode($data);, else show your expected output.