i have json array that i generate from php. However the format is not what i want. i have related questions but it is not the format i want Please see below what i did and tried vs what i want
//////////////
$data variable array
///////////////
Array
(
[0] => Array
(
[id] => 2
[start_date] => 2018-05-17 08:40
[end_date] => 2018-05-17 09:00
)
[1] => Array
(
[id] => 3
[start_date] => 2018-05-17 08:40
[end_date] => 2018-05-17 09:00
)
)
This is what i do
$array[] = $data;
echo json_encode($array);
The output
[
{"id":2,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"},
{"id":3,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"}
]
This is what i tried
$array["data"] = $data;
echo json_encode($array);
The output
{"data":
{"id":2,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"},
{"id":3,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"}
}
The output i want
{
"data": [
{"id":2,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"},
{"id":3,"start_date":"2018-05-17 08:40","end_date":"2018-05-17 09:00"}
]
}