문제

I know why i am getting this illegal offset, it is because i am comparing against part of the array which isn't set.

I want to know if there is any way of avoiding this, currently i am just hiding the errors and it works fine (using error_reporting(0);).

I don't think hiding the errors would be very good practice and this is why i ask =]

`

for ($i=0; $i < $len; $i++){

  if($book[$i]["bookedFor"]!=$book[$i+1]["bookedFor"]){    //ILLEGAL OFFSET HERE

    echo "<tr>";
    echo "<td>" . $book[$i]["roomName"] . "</td>";
    echo "<td>" . $book[$i]['bookedFor'] . "</td>";
    echo "<td>";
    for ($j=0; $j < $len; $j++){ 

        if($book[$i]["bookedFor"]==$book[$j]["bookedFor"]){

            if(!empty($book[$j]['resourceName'])){

                if($book[$i]["bookedFor"]!=$book[$j+1]["bookedFor"]){    //ILLEGAL OFFSET HERE

                    echo $book[$j]['resourceName'];

                } else {

                    echo $book[$j]['resourceName'] . ", ";
                }
            }
        }
    }
    echo "</td>";
    echo "</tr>";
  }
}

`

Many thanks

도움이 되었습니까?

해결책

if (!array_key_exists($i+1, $book)) {
    $book[$i+1] = "Closed";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top