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 );