我有一些基本代码,可以从上一页的表单中获取结果,并将其编码为文本文件。出于某种原因,它对其进行了正确编码,然后创建了一个只有空值的第二个数组。
(每个数组中有相同数量的值)
老实说,我不知道是什么原因造成的。
这是编码代码:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$date = $_POST['date'];
$destination = $_POST['destination'];
$msg = $_POST['msg'];
//TODO the file write here VV, use 'a' instead of 'w' too ADD to the file instead of REWRITING IT.
$arr = [$name,$email,$date,$destination,$msg];
$write = json_encode($arr);
echo $write;
$file = fopen('data.txt', 'a');
fwrite($file, $write);
fclose($file);
// echo $arr[];
?>
这是 .txt 文件中的结果:
["Simon","example@example.com","0101-01-01T01:01","Ohio","Message here"][null,null,null,null,null]
(如果有帮助,它将它们写在同一行上)
我不想要这个空数组,因为它会搞乱我需要做的一些事情。有什么想法吗
缥缈止盈