首页 > 后端开发 > php教程 > json数据格式拼凑,数组合并,

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

WBOY
发布: 2016-06-13 10:00:39
原创
980 人浏览过

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"}
]
}
*/

?>

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板