Oscar C. Oscar C. - 1 year ago 124
JSON Question

PHP encode json 3 in 1 response

I have in a file 3 json responses. I need to encode them in one Json with 3 Objects inside which are the three responses which I have separated. Any help?-

echo json_encode(array('result_temperatura'=>$output_result_temperatura));

echo json_encode(array('result_presion'=>$output_result_presion));

echo json_encode(array('result_altitud'=>$output_result_altitud));

Answer Source

Build an array or object with the data:

$result = array('result_temperatura'=>$output_result_temperatura,

echo json_encode($result);

Or if you actually want a multidimensional array:

$result[] = array('result_temperatura'=>$output_result_temperatura);
$result[] = array('result_presion'=>$output_result_presion);
$result[] = array('result_altitud'=>$output_result_altitud);

echo json_encode($result);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download