Json data format patchwork, array merge, help! There are three arrays $ arrarray (Zhangsan, Lisi, Wangwu); $ arr2array (100,200,300); $ arr3array (50,60, 70); if he Ping makes it into another array $ array, finally, echojson_encode ($ array) outputs the following format: {& quot; total & quot;: & quot json data format patchwork, array merging, for help!
There are three arrays
$ Arr = array ('Zhang San', 'Li Si', 'Wang Wu ');
$ Arr2 = array (100,200,300 );
$ Arr3 = array (50, 60, 70 );
For example, Heping makes another array $ array, and finally echo json_encode ($ array) outputs the following format:
{"Total": "3 ",
"Result ":[
{"Date": "1", "name": "Zhang San", "value": "100", "other": "50 "},
{"Date": "1", "name": "", "value": "200", "other": "60 "},
{"Date": "1", "name": "Wang Wu", "value": "300", "other": "70 "}
]
}
Guys, Help...
------ Solution --------------------
$ Arr = array ('Zhang San', 'Li Si', 'Wang Wu ');
$ Arr2 = array (100,200,300 );
$ Arr3 = array (50, 60, 70 );
$ Date = time ();
$ Result ['total'] = sizeof ($ arr );
For ($ I = 0; $ I {
$ Result ['result'] [] = array ("date" => $ date, "name" => $ arr [$ I], "value" => $ arr2 [$ I], "other" => $ arr3 [$ I]);
}
Echo json_encode ($ result );
/*
{"Total": "3 ",
"Result ":[
{"Date": "1", "name": "Zhang San", "value": "100", "other": "50 "},
{"Date": "1", "name": "", "value": "200", "other": "60 "},
{"Date": "1", "name": "Wang Wu", "value": "300", "other": "70 "}
]
}
*/
?>