热搜:NVER 

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

2024-05-17 10:00:02
 json数据格式拼凑,数组合并,

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…

------解决方案--------------------
<?php
$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"}
]
}
*/

?>