I know myarray[1] and myarray["1"] point to the same thing. But even with that knowledge I am still having a bit of trouble.
I have this:
$KEYS = ["1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "J",
"K", "L", "M", "N", "P", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"];
$KEYS_LENGTH = count($KEYS);
$KEYS_INVERSE = array();
for ($i = 0; $i < $KEYS_LENGTH; $i++) {
$KEYS_INVERSE[$KEYS[$i]] = $i;
}
Then later on I do this:
$str = "A21"; // Some random string built with the letters of $KEYS
$len = strlen($str);
for($i=0;$i<$len;$i++){
if ($KEYS_INVERSE[$str[$i]] == "undefined") return false; // AN ERROR - This is the problem line
else{
// Carry on happily doing stuff
}
}
Everything goes great. When $str[$i] is "A" that is fine. Even when $str[$i] is "2" that is fine. But when $str[$i] is "1" it triggers that 'return false;' believing $KEYS_INVERSE[$str[$i]] == "undefined".
What is going wrong?