$_POST['日期'], '哪一餐'=> $_POST['哪一餐'], '吃什麼'=> $_POST['吃什麼'], '金額'=> $_POST['金額'], ); $array_data[] = $extra; $final_data = json_encode($array_data); file_put_contents("test.json", $final_data); header("Refresh:0"); } $json_file = file_get_contents("test.json"); $data = json_decode($json_file, true); $sum = 0; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; foreach((array)$data as $row) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $sum += $row['金額']; } echo "
".'日期'."".'哪一餐'."".'吃什麼'."".'金額'."
".$row['日期']."".$row['哪一餐']."".$row['吃什麼']."".$row['金額']."
"; echo "

"; $newData = array('日期' => "2020.20.20", '哪一餐'=>'宵夜', '吃什麼'=>'豆花', '金額'=>60); $json_string = json_encode($data); file_put_contents("test.json", $json_string); echo <<< _html
新增資料
日期:  哪一餐:  吃什麼:  金額: 
_html; echo "
"; echo "

總計金額:$sum

"; ?>