PHP JSON array problem

Source: Internet
Author: User
PHP json array problem, $result 1 and $result2 two arrays merged into one, output echo json_encode ($result 1) separately; Echo Json_encode ($result 2);
Final output effect:
{
"id": "111",
"Image_name": "My Bedroom",
"Image_url": "D:/image/a.png",

comments:[{
"UID", "122",
"CNAME": "Xiaoming",
"CTime", "2014-12-12",
}]
}
To do this, echo json_encode (Array ($result 1, $result 2)), so the output is not correct, it is added directly to the back, but not into a separate array

What should I do?


Reply to discussion (solution)

What are your $result 1, $result 2?

The individual array is what kind of, post the final results look.

echo Json_encode (Array ("content" = $result 1), $result 2)) is that so?

$result 1 and $result 2?

Echo Json_encode (Array_merge ($result 1, Array ("comments" = $result 2)))

What are your $result 1, $result 2?


$result 1 is "id": "111",
"Image_name": "My Bedroom",
"Image_url": "D:/image/a.png",
These
$result 2

The individual array is what kind of, post the final results look.


The individual is "id": "111",
"Image_name": "My Bedroom",
"Image_url": "D:/image/a.png",
The back is $RESULT2.

$result 1 and $result 2?


$result 1 is the top half, $result 2 is the lower half.

$result 1 = Array (  ' id ' = = 111,  ' image_name ' = ' my bedroom ',  ' image_url ' = ' d:/image/a.png ',); $result 2 = Array (' comments ' = = Array (' uid ' = ' = '      122,      ' cname ' = ' Xiao Ming ',      ' ctime ' = ' 2014-12-12 ',    ),  ), Echo Json_encode (Array_merge ($result 1, $result 2));

$result 1 = array (' id ' = ' = ' 111 ', ' image_name ' = ' my bedroom ', ' image_url ' = ' d:/image/a.png '); $result 2 = Array (' Comments ' = = Array (' uid ' = ' 122 ', ' cname ' = ' xiaoming ', ' ctime ' = ' 2014-12-12 ')); $result = Array_merge ($ RESULT1, $result 2); Echo Json_encode ($result);

I think the landlord's problem seems not so simple, give two arrays let you call the function?
I have seen a long problem is not understand the meaning.

I think the landlord's problem seems not so simple, give two arrays let you call the function?
I have seen a long problem is not understand the meaning.


Is that there are two arrays that output them as a JSON array
  • 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.