Hi guys im having some trouble creating the json i need to send to my datatable JS. I see that in my output i get the ''keys'' inside the array and in the one that i need i dont get them. How can i creat an array without those keys or i dont need an array inside another array? So this is the output of the JSON that i need:
{
"data": [{
"DT_RowId": "row_1",
"first_name": "Tiger",
"last_name": "Nixon",
"position": "System Architect",
"email": "[email protected]",
"office": "Edinburgh",
"extn": 5421,
"age": 61,
"salary": 20800,
"start_date": "2011-04-25"
},
{
"DT_RowId": "row_1",
"first_name": "Tiger",
"last_name": "Nixon",
"position": "System Architect",
"email": "[email protected]",
"office": "Edinburgh",
"extn": 5421,
"age": 61,
"salary": 20800,
"start_date": "2011-04-25"
}
]
}
what i have is this:
$json = array(
'Data' => array(
'1' => array(
"DT_RowId" => "row_1",
"first_name"=> "Tiger",
"last_name"=> "Nixon",
"position"=> "System Architect",
"email"=> "[email protected]",
"office"=> "Edinburgh",
"extn"=> 5421,
"age"=> 61,
"salary"=> 20800,
"start_date"=> "2011-04-25"
),
'2' => array(
"DT_RowId" => "row_1",
"first_name"=> "Tiger",
"last_name"=> "Nixon",
"position"=> "System Architect",
"email"=> "[email protected]",
"office"=> "Edinburgh",
"extn" => 5421,
"age"=> 61,
"salary"=> 20800,
"start_date"=> "2011-04-25"
),
));
echo json_encode($json, JSON_FORCE_OBJECT);
and the output is:
{
"Data": {
"1": {
"DT_RowId": "row_1",
"first_name": "Tiger",
"last_name": "Nixon",
"position": "System Architect",
"email": "[email protected]",
"office": "Edinburgh",
"extn": 5421,
"age": 61,
"salary": 20800,
"start_date": "2011-04-25"
},
"2": {
"DT_RowId": "row_1",
"first_name": "Tiger",
"last_name": "Nixon",
"position": "System Architect",
"email": "[email protected]",
"office": "Edinburgh",
"extn": 5421,
"age": 61,
"salary": 20800,
"start_date": "2011-04-25"
}
}
}