Phpjson array problems

Source: Internet
Author: User
Phpjson array php & nbsp; json Array problem, $ result1 and $ result2 arrays are merged into one and output separately & nbsp; echo & nbsp; json_encode ($ result1 ); & nbsp; echo & nbsp; json_encode ($ result2); & nbsp; the output result is a json Array of php files.
Php json Array problem, $ result1 and $ result2 arrays are merged into one, and the echo json_encode ($ result1) is output separately; echo json_encode ($ result2 );
Final output:
{
"Id": "111 ",
"Image_name": "My bedroom",
"Image_url": "d:/image/a.png ",

Comments :[{
Uid, 122 ",
"Cname": "James",
"Ctime ",
}]
}
Echo json_encode (array ($ result1, $ result2) for this effect. if the output is incorrect, it is added directly to the end, instead of a separate array.

What should I do?
------ Solution ----------------------
What are your $ result1 and $ result2?
------ Solution ----------------------

$ Result1 = array (
'Id' => '123 ',
'Image _ name' => 'My bedroom ',
'Image _ url' => 'd:/image/a.png'
);

$ Result2 = array (
'Comments' => array (
Array (
'Uid' => '123 ',
'Cname' => 'xiaoming ',
'Ctime' => '2017-12-12'
)
)
);

$ Result = array_merge ($ result1, $ result2 );
Echo json_encode ($ result );

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.