I’ve got a short question that I’ve been wondering about for a while. There is a perfect workaround, but I’d like to know what the problem really is.
I’ve got an array ($lines) consisting of underlying associative arrays. I want to get the indexes of one (basically any random one) of those underlying arrays, so I use:
$headers = array_keys($lines[0]);
However, this gives me back the following error:
Warning: array_keys() expects parameter 1 to be array, null given
But then, when I use this instead:
$line0 = $lines[0];
$headers = array_keys($line0);
Everything works exactly as I want it to. Now as far as I can see, these two should be perfectly equivalent, so I was wondering if this is a bug in PHP, or if I just fail to understand something here.
PHP version is 5.3.1
The $lines array looks like this in my test case:
Array (
[0] => Array
(
[id] => 00
[name] => John Doe
)
[1] => Array
(
[id] => 007
[name] => James Bond
)
)
I can’t reproduce.
I wrote the following file:
And it outputs correctly:
So I guess it’s either a bug in your program or in your php version but nothing “normal”.