$response = array(
"aaData" => $data
);
echo json_encode($response);
how to add more name = '123', data = $data
CodePudding user response:
You can push data into the array or you can define the array and assign value by key Example
$response = [];
$response['name'] = '123';
$response['data'] = 'mydata';
$response['aaData'] = $data;
echo json_decode($response);
$data can be array like this
$data =[];
$data['name'] = "ABCD";
$data['id'] = 1;
$response['aaData'] = $data;
By loop
$dataTableResponse = [];
for($i=0;$i<=5;$i ) {
$data['name'] = "A";
$data['id'] = $i;
$dataTableResponse[] = $data;
}
$response['aaData'] = $dataTableResponse;
echo json_encode($response);