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