I try to access an array element, but for some reason this gives me some trouble.
So I got this array inside $lead
:
Array
(
["City"] => Other
[Company Name] =>
[Company Email] =>
[Contact Form URL] =>
[Comments] =>
)
And I try to access it like this:
var_dump($lead['"City"']);
But for some reason I get an undefined index error:
Notice: Undefined index: "City"
And I have no idea why that is?
EDIT:
This is the output when I use highlight_string(print_r($lead, TRUE));
:
Array
(
["City"] => Other
[Company Name] =>
[Company Email] =>
[Contact Form URL] =>
[Comments] =>
)
Also with this code:
foreach($lead as $k => $v){
var_dump($k);
die();
}
I get:
string(9) ""City""
So thanks to the comments it seems like I got an UTF-8 BOM character (EF BB BF) at the start of my key and that is why I couldn't access it. It also seemed that Stack Overflow stripped away the character when I posted it here.
With this code:
foreach($lead as $k => $v){
var_dump($k);
die();
}
It showed that the key had to be 9 bytes long.
string(9) ""City""
//↑
With the help of a hex viewer you could also see the EF BB BF
character. So the solution is to use a foreach loop to get the array element or use the correct key:
foreach($lead as $k => $v){
echo $v;
break;
}
or
echo $lead[chr(0xEF) . chr(0xBB) . chr(0xBF) . '"City"'];