This one is a real head scratcher. I’ve exhausted every possible avenue with Gemini AI and even that can’t seem to solve this one.
So, I have this code which I’ve set up as a test:
$nz_array = array('NZ','nz');
$users_countrycode = do_shortcode('[userip_location type="countrycode"]');
echo("Needle = "" . $users_countrycode . ""<br />");
var_dump($nz_array);
echo("<br />Haystack = "" . $nz_array[0] . """);
if(is_string($users_countrycode)){
echo("<br />Needle is string");
}
if(is_string($nz_array[0])){
echo("<br />Haystack is string");
}
if($users_countrycode == $nz_array[0]){
echo("<br />Yes, " . $users_countrycode . " is equal to " . $nz_array[0]);
}
if(in_array($users_countrycode,$nz_array)){
echo('<br />YES, is in array!');
}
The resulting output is:
Needle = "NZ"
array(2) { [0]=> string(2) "NZ" [1]=> string(2) "nz" }
Haystack = "NZ"
Needle is string
Haystack is string
Note that both the needle and the haystack result as “NZ” and are both strings (note also that I have forced the code to display quotation marks on each side of the resulting “NZ” values to show that there are no hidden spaces, etc), and yet the lines,
if($users_countrycode == $nz_array[0])
and,
if(in_array($users_countrycode,$nz_array))
both result in no output at all! Therefore $users_countrycode does not equal $nz_array[0] and $users_countrycode is not being found in the $nz_array array.
I cannot figure out why. This always used to work perfectly, but has somehow suddenly stopped working for some obscure reason.
Any ideas?