FIrst, PHP (and, in fact, nearly all programming languages) starts counting at 0. So if you have an array with two elements, they'll have indexes 0 and 1. But count() doesn't return the highest index, it returns the number of elements, so it would return 2. And since the highest index in your array is 1, $array[2] doesn't have a value. I recommend using count($array) - 1.

Second, the operator for equals is ==, not =. Not to mention you should be using != (as in $a != $b) intead of !$a == $b. This will alleviate a lot of operator precedece issues.

Third, your comparison won't work. You cannot string together a bunch of boolean operators and expect them to work. PHP does not work like natural language. You can't just say "A is equal to B or C or D". Instead, you have to be very specific: "(A is equal to B) or (A is equal to C) or (A is equal to D)". A working version of your code (significantly adjusted for readability) would look more like this: