Home  >  Article  >  Backend Development  >  php json数组有关问题

php json数组有关问题

WBOY
WBOYOriginal
2016-06-13 12:08:12926browse

php json数组问题
php json数组问题,$result1和$result2两个数组合并成一个,单独输出  echo json_encode($result1);   echo json_encode($result2);   
最后输出效果:
{
“id”:”111”,
 “image_name”:”我的卧室“,
“image_url”:“d:/image/a.png”,

 comments:[{
“uid”,“122”,
“cname“:”小明“,
“ctime”,“2014-12-12”,
}]
}
做出这种效果,  echo json_encode( array($result1, $result2) );这样输出的不对,是直接在后面加上了,而没有成单独的数组

该怎么做呢
------解决思路----------------------
你的 $result1、$result2 都是什么?
------解决思路----------------------

<br />$result1 = array(<br />	'id' => '111',<br />	'image_name' => '我的卧室',<br />	'image_url' => 'd:/image/a.png'<br />);<br /><br />$result2 = array(<br />	'comments' => array(<br />		array(<br />			'uid' => '122',<br />			'cname' => '小明',<br />			'ctime' => '2014-12-12'<br />		)<br />	)<br />);<br /><br />$result = array_merge($result1, $result2);<br />echo json_encode($result);<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn