JSON データ形式の結合、配列の結合、助けてください!
配列は 3 つあります
$arr = array('Zhang San','Li Si','Wang Wu');
$arr2 = array(100,200,300);
$arr3 = array( 50 ,60,70);
別の配列 $array を平坦化する方法、そして最後に echo json_encode($array) は次の形式を出力します
{"total": " 3",
"結果":[
{"日付":"1","名前":"張三","値":"100","その他":"50"},
{"日付":"1","名前":"李思","値":"200","その他":"60"},
{"日付":"1", " name":"王五","value":"300","other":"70"}
]
}
兄弟、助けてください...
-----解決策---------
$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);
/*
{"合計":"3",
"結果":[
{"日付":"1","名前":"张三","値": "100","other":"50"},
{"date":"1","name":"李思","value":"200","other":"60"} ,
{"日付":"1","名前":"王五","値":"300","その他":"70"}
]
}
* /
?>