大家好,
我正在練習 php 陣列,我的編輯器無法檢測到我的 php 出現的錯誤,但是當它運行時,我收到錯誤訊息
警告:php 中未定義的陣列鍵 3
同時仍然正確列印輸出。
我的 html 表單是:
<!DOCTYPE html>
<html>
<head><title>Number of Students</title></head>
<body>
<form action="Q4.php">
<table>
<tr>
<td>Number of Students:</td>
<td><input type="text" name="num" size="5"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
我的 php 表單是:
<!DOCTYPE html>
<html>
<head><title>Number of Students</title></head>
<body>
<form action="Q4index.php">
<table border=1 cellspacing=0 cellpadding=3>
<tr><th>Student</th><th>Mark</th></tr>
<?php
$num = $_GET["num"];
for($i=1; $i<=$num; $i ){
echo"<tr><td><input type=text name=stud[] size=7></td>
<td><input type=text name=mark[] size=5></td></tr>";
}
?>
<tr><td><input type="submit" value="Submit"></td><td><input type="Reset" value="Reset"</td></tr>
</table>
</form>
</body>
</html>
和運行它的php程式檔案是:
<!DOCTYPE html>
<html>
<head><title></title></head>
<body>
<h3>The students who passed the exam:</h3>
<table border="1" cellspacing="0" cellpadding="3">
<tr><th>Name</th><th>Total Mark</th></tr>
<?php
//Declaration of Arrays
$name=$_GET["stud"];
$mark=$_GET["mark"];
//Loop and Conditions
for($i=0; $i<=count($name); $i ){
if($mark[$i]>=50){
//Printing
echo"<tr><td>$name[$i]</td><td>$mark[$i]</td></tr>";}
}
?>
</table>
</body>
</html>
在表單中輸入示例資料并嘗試執行代碼后,會出現此錯誤訊息:
錯誤截圖
誰能告訴我我的代碼丟失了什么?預先感謝您,我非常感謝您對我的問題的耐心:)
uj5u.com熱心網友回復:
洗掉條件“$i<=count($name)”中的“=”。寫“$i < count($name)”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/348194.html
