if (!array_key_exists($i+1, $book)) {
$book[$i+1] = "Closed";
}
Array offset causing problems when comparing
题
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
解决方案
不隶属于 StackOverflow