我在瀏覽器調試器中收到警告,但PHP仍然有效。爲什麼我會收到警告?提前致謝。PHP中的foreach()的警告,但仍然循環
Warning: Invalid argument supplied for foreach().
HTML:
<form action="" method="post" name="savefile">
<input id="uniqueID" value="ZF4446A3GZ" name="filename" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input value="Done!" name="submitsave" type="submit">
</form>
PHP:
<?php
if (isset($_POST)){
foreach($_POST["textdata"] as $text){
if(!file_exists($_POST['filename'] . ".txt")){
$file = tmpfile();
}
$file = fopen($_POST['filename'] . ".txt","a+");
while(!feof($file)){
$old = $old . fgets($file);
}
file_put_contents($_POST['filename'] . ".txt", trim($text).PHP_EOL, FILE_APPEND);
fclose($file);
}
}
?>
支票本,希望這將幫助ü... https://www.euperia.com/development/fix-php-warning-invalid-argument-supplied-foreach/1230和http://計算器.com/questions/19983912/warning-invalid-argument-supplied-for-foreach-in-php – Aru 2015-02-10 04:33:05