我将以下数据重复了五次,并希望返回数组并将数组写入我的 csv 文件:
<strong>Inventory number:</strong>
<input name="inv[]" type="text" size="10" id="inv[]"/>
<strong>Description:</strong>
<input name="des[]" type="text" size="30"id="des[]"/>
<strong>Inventory number:</strong>
<input name="inv[]" type="text" size="10" id="inv[]"/>
<strong>Description:</strong>
<input name="des[]" type="text" size="30"id="des[]"/>
我做了一个foreach:
for ($i = 0, $rowcount = count($_POST['inv']); $i < $rowcount; $i++)
{
$inv = $_POST['inv'][$i]; // get inventory
$des = $_POST['des'][$i]; // get description
}
然后有一个写命令:
if(empty($errorMessage))
{
$fs = fopen("data.csv","a") or die("Unable to open file for output");
fwrite($fs,$sn . ", " . $givenname . ", " . $mail . ", " . $uid . ", " . $inv . ", " . $des . ", " . date("Y.m.d H:i:s") . "\n");
fclose($fs);
$destination_url = "receipt.php";
header("Location: $destination_url");
exit;
}
但它只将最后一个数组写入 csv 文件。
你能帮我吗?谢谢