0

I am facing a problem that shows the output undefined offset :0 in multiple lines. I can't understand what type of error it is. Can anyone tell me why such error occurs in PHP. I've looked on other posts but haven't found anything similar that could help me solve this. Any help/suggestions would be appreciated.

$m=0;
    for ($i=0; $i < Sizeof($questionlist)/15 ; $i++){
      $question = $questionlist[$i];
    //   $question = $questionlist[$k];
      while($m<15*($i+1)){//loop for every question

        $FuncName = $question[$m];  //Notice: Undefined offset: 0
        $m++;
        print_r($FuncName);
        $FuncParam = $question[$m]; //Notice: Undefined offset: 1
        $m++;
        $Constraint = $question[$m]; //Notice: Undefined offset: 2
        $m++;
        $StuRes = $question[$m]; //Notice: Undefined offset: 3
        $m++;
        $QValue = $question[$m]; //Notice: Undefined offset: 4
        $m++;
        $CaseOneI = $question[$m]; //Notice: Undefined offset: 5
        $m++;
        $CaseOneO = $question[$m]; //Notice: Undefined offset: 6
        $m++;
        $CaseTwoI = $question[$m]; //Notice: Undefined offset: 7
        $m++;
        $CaseTwoO = $question[$m]; //Notice: Undefined offset: 8
        $m++;
        $CaseThreeI = $question[$m]; //Notice: Undefined offset: 9
        $m++;
        $CaseThreeO = $question[$m]; //Notice: Undefined offset: 10
        $m++; 
        $CaseFourI = $question[$m]; //Notice: Undefined offset: 11
        $m++;
        $CaseFourO = $question[$m]; //Notice: Undefined offset: 12
        $m++;
        $CaseFiveI = $question[$m]; //Notice: Undefined offset: 13
        $m++;
        $CaseFiveO = $question[$m]; //Notice: Undefined offset: 14
        $m++;

yuchen
  • 1
  • 1
    Can you show what `var_dump($questionList);` looks like? – Barmar Apr 21 '20 at 18:09
  • BTW, if you want to set lots of variables from an array, you can do `list($FuncName, $FuncParam, $Constraint, ...) = $question[$m];` instead of lots of separate assignments. – Barmar Apr 21 '20 at 18:10
  • I don't understand why your inner loop is limited by `$i+1`. Does `$questionList[2]` have more elements than `$questionList[1]`? – Barmar Apr 21 '20 at 18:12
  • Are you trying to loop over `$questionList` in groups of 15? Then you should be using `array_slice()` or `array_chunk()`. – Barmar Apr 21 '20 at 18:13
  • $question is not an array, this is the reason. Now you have to check what is the architecture of $questionList. If you are fetching this from database then use appropriate function like fectch_array(). – SayAz Apr 21 '20 at 18:13
  • It will be better if you show us $questionlist, and describe what you want to implement. – SayAz Apr 21 '20 at 18:14

0 Answers0