[英]Why i'm getting Undefined offset: 0 in this php code
我寫了這段代碼,我遇到了這個錯誤,我嘗試了每個錯誤,但似乎都無法正常工作,我已經對第55行的地方發表了評論,其中我開始出錯
function calculate_result()
{
$option_number = array('option_a'=>'1','option_b'=>'2','option_c'=>'3','option_d'=>'4');
$answers = array();
$total_questions = $this->quiz_model->return_number_of_questions($this->input->post('quiz_number'));
if($total_questions > 0)
{
for($i=1; $i <= $total_questions; $i++)
{
//line 55 $answers[$i] = $option_number[$this->input->post('question_'.$i)];
}
print_r($answers);
}
else
{
show_404();
}
//print_r($answers);
}
遇到PHP錯誤
嚴重程度:注意
消息:未定義的偏移量:0
文件名:controllers / quiz.php
行號:55
改變這個...
for($i=1; $i <= $total_questions; $i++)
為此...
for($i=0; $i <= $total_questions; $i++)
在該行上有兩個索引,在左側有$i
且它不是零。
因此,問題必須出在右側表達式上,其中$this->input->post('question_'.$i)
可能返回0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.