Php json Array problem: $ result1 and $ result2 arrays are merged into one, and 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?
Reply to discussion (solution)
What are your $ result1 and $ result2?
What is a separate array? paste the final result to see it.
Echo json_encode (array ("content" => $ result1), $ result2) is that true?
$ Result1 and $ result2 both? Yes? Output.
Echo json_encode (array_merge ($ result1, array ("comments" => $ result2 ??
What are your $ result1 and $ result2?
$ Result 1 is "id": "111 ",
"Image_name": "My bedroom",
"Image_url": "d:/image/a.png ",
These,
$ Result 2
What is a separate array? paste the final result to see it.
It is the "id": "111 ",
"Image_name": "My bedroom",
"Image_url": "d:/image/a.png ",
Followed by $ result2
$ Result1 and $ result2 both? Yes? Output.
$ Result1 indicates the upper half, and $ result2 indicates the lower half.
$ Result1 = array ('id' => 111, 'image _ name' => 'My bedroom ', 'image _ url' => 'd: /image/a.png ',); $ result2 = array ('comments' => array ('uid' => 122, 'cname' => 'xiaoming ', 'ctime' => '2017-12-12 ',); echo json_encode (array_merge ($ result1, $ result2 ));
$ Result1 = array ('id' => '000000', 'image _ name' => 'My bedroom ', 'image _ url' => 'd: /image/a.png '); $ result2 = array ('comments' => array ('uid' => '000000', 'cname' => 'xiaoming ', 'ctime' => '1970-12-12 '); $ result = array_merge ($ result1, $ result2); echo json_encode ($ result );
I think the problem with the landlord seems to be not that simple. do you want to call functions for two arrays?
I did not understand the problem after reading it for a long time.
I think the problem with the landlord seems to be not that simple. do you want to call functions for two arrays?
I did not understand the problem after reading it for a long time.
There are two arrays that output them into a json Array.