您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php json数组问题

2024/4/15 19:33:32发布23次查看
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 都是什么?
单独的数组是什么样的,贴出最后结果看看。
echo json_encode( array(array(content=>$result1), $result2) )  是这样?
$result1 和 $result2 都?有?出。
echo json_encode(array_merge($result1, array(comments=>$result2)))   这样??
你的 $result1、$result2 都是什么?
$result 1 就是“id”:”111”,
 “image_name”:”我的卧室“,
“image_url”:“d:/image/a.png”,
这些,
$result 2 
单独的数组是什么样的,贴出最后结果看看。
单独的就是“id”:”111”,
 “image_name”:”我的卧室“,
“image_url”:“d:/image/a.png”,
后面的是$result2
$result1 和 $result2 都?有?出。
$result1就是上半部,$result2就是下半部 $result1 = array( 'id' => 111, 'image_name' => '我的卧室', 'image_url' => 'd:/image/a.png',);$result2 = array( 'comments' => array( array( 'uid' => 122, 'cname' => '小明', 'ctime' => '2014-12-12', ), ),);echo json_encode(array_merge($result1, $result2));
$result1 = array( 'id' => '111', 'image_name' => '我的卧室', 'image_url' => 'd:/image/a.png');$result2 = array( 'comments' => array( array( 'uid' => '122', 'cname' => '小明', 'ctime' => '2014-12-12' ) ));$result = array_merge($result1, $result2);echo json_encode($result);
我觉得楼主的问题似乎没有那么简单,给两个数组让你调用函数吗?
我看了半天问题就是没看懂意思.
我觉得楼主的问题似乎没有那么简单,给两个数组让你调用函数吗?
我看了半天问题就是没看懂意思.
就是有两个数组,把他们输出成一个json数组
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product