Skip to content
Advertisement

PHP: Why does this return “undefined offset” every time?

So basically this is an algorithm I made for a battleships game. I’m having problems with the while loop, I want to have the code inside the do while loop keep repeating, if the generated values already exist in a multidimensional array, and it looks like it actually works, because it generates correct values, but I keep getting the error “UNDEFINED OFFSET”, why? And yes, I know it’s ugly code, but I’m really just interested in the error, because the program works fine otherwise

enter image description here

JavaScript

Advertisement

Answer

Because a for loop will increment the counter and then test it your do-while limiting statement was using $x = 5 and that blew

JavaScript

beyond its bounds.

All I did was $x--; as the last thing before completing the loop and bingo. No erors.

JavaScript

Its a little dodgy controlling an outer loop with the result of something else going on in the loop IMO

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement