Home  >  Article  >  Backend Development  >  json数据格式拼凑,数组合并,

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

WBOY
WBOYOriginal
2016-06-13 13:51:241188browse

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

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn