Json data format splicing, array merging,

Source: Internet
Author: User
Json data format patchwork, array merge, 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, He Ping makes another array $ array, and finally echojson_encode ($ arr json data format patchwork, array merge, 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 "}
]
}
*/

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.