php关键数组 json数组,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 都是什么?

单独的数组是什么样的,贴出最后结果看看。

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数组

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值