php json数组问题

php中文网
发布: 2016-06-23 13:47:23
原创
1037人浏览过

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) );这样输出的不对,是直接在后面加上了,而没有成单独的数组

该怎么做呢

Find JSON Path Online
Find JSON Path Online

Easily find JSON paths within JSON objects using our intuitive Json Path Finder

Find JSON Path Online 30
查看详情 Find JSON Path Online

回复讨论(解决方案)

你的 $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速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号