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

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript开发工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境