欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

json数据格式拼凑,数组合并,

程序员文章站 2023-12-28 22:50:40
...
json数据格式拼凑,数组合并,求助!
有三个数组
$arr = array('张三','李四','王五');
$arr2 = array(100,200,300);
$arr3 = array(50,60,70);


如何平凑成另外一个数组$array,最后echo json_encode($array)输出如下格式


{"total":"3",
"result":[
{"date":"1","name":"张三","value":"100","other":"50"},
{"date":"1","name":"李四","value":"200","other":"60"},
{"date":"1","name":"王五","value":"300","other":"70"}
]
}


兄弟们,Help…

------解决方案--------------------
$arr = array('张三','李四','王五');
$arr2 = array(100,200,300);
$arr3 = array(50,60,70);
$date=time();
$result['total']=sizeof($arr);
for($i=0;$i{

$result['result'][]=array("date"=>$date,"name"=>$arr[$i],"value"=>$arr2[$i],"other"=>$arr3[$i]);


}
echo json_encode($result);


/*
{"total":"3",
"result":[
{"date":"1","name":"张三","value":"100","other":"50"},
{"date":"1","name":"李四","value":"200","other":"60"},
{"date":"1","name":"王五","value":"300","other":"70"}
]
}
*/

?>
json数据格式拼凑,数组合并,

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


上一篇:

下一篇: