如何在json文件中刪除我的數據,繼承人我的json文件數據,我想清除我的json文件的數據。如何從json文件中取消設置
{"name":null,"timestart":"00:00","timeend":"00:00","day":null},
{"name":"henrix","timestart":"7:00","timeend":"7:30","day":"tuesday"}]
我想這代碼,但它不會刪除數據,其保存的另一個數據,但其空
<?php
$file = 'timetable.json';
$json_file = file_get_contents($file);
$file_content = json_decode($json_file);
foreach ($file_content as $key => $value) {
$name = $file_content[$key]->name;
$timestart = date("H:i", strtotime($file_content[$key]->timestart));
$timeend = date("H:i", strtotime($file_content[$key]->timeend));
$day = $file_content[$key]->day;
$reservations[] = array(
"name" => $name,
'timestart'=> $timestart,
'timeend'=> $timeend,
'day'=> $day
);
}
$reservations[] = array(
"name" => null,
'timestart'=> null,
'timeend'=> null,
'day'=> null
);
file_put_contents($file, json_encode($reservations));
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'henriks.php';
header("Location: http://$host$uri/$extra");
exit();
?>
'code' $ value){ \t unset($ file_content [$ key]); } $保留[] =陣列( 「名稱」=>空, 'timestart'=>空, 'timeend'=>空, '天'=>空 ); file_put_contents($ file,json_encode($ reservations)); $ host = $ _SERVER ['HTTP_HOST']; $ uri = rtrim(dirname($ _ SERVER ['PHP_SELF']),'/ \'); $ extra ='henriks.php'; header(「Location:http:// $ host $ uri/$ extra」); exit(); ?> –