First, im a beginner in PHP so please bear with me.
I want to create something like this JSON array :
{
children: [
{
id: "1"
user_id: "1"
name: "Test"
gender: "M"
born_date: "2014-10-01"
born_hour: "12:12:12"
hospital: "test hospital"
}-
}-
{
id: "2"
user_id: "1"
name: "test2"
gender: "F"
born_date: "2014-10-06"
born_hour: null
hospital: null
}-
]
result: "true"
total: 2
}
To make my question easier, this is an easy to read JSON i want to create (you can think mobiles as children in my case) :

The children should become the parent and array. This is what i accomplished so far :
{
0: {
children: {
id: "1"
user_id: "1"
name: "Test"
gender: "M"
born_date: "2014-10-01"
born_hour: "12:12:12"
hospital: "test hospital"
}-
}-
1: {
children: {
id: "2"
user_id: "1"
name: "test2"
gender: "F"
born_date: "2014-10-06"
born_hour: null
hospital: null
}-
}-
result: "true"
total: 2
}
The children is not the parent of the items and not in array ([]).
This is my code to generate the above JSON :
$resultArray = array('result' => 'true', 'total' => $size);
foreach($result as $child)
{
if($child)
{
//add to array
$resultArray[] = array('children' => array('id' => $child['id'],
'user_id' => $child['user_id'],
'name' => $child['name'],
'gender' => $child['gender'],
'born_date' => $child['born_date'],
'born_hour' => $child['born_hour'],
'hospital' => $child['hospital']));
}
}
$this->response($resultArray, 200);
Please kindly help me. Thanks for your help.