I’ve been getting error from accessing array with string offsets. The array looks something like this:
$array = array(
"first" => array("one","two","three"),
"second" => array("blabla"),
"third" => array("something","else"),
"fourth" => array("next","nextnext","nextnextnext")
);
I’m trying to get one of the inside arrays depending on string I have and I use that string as offset, like this:
$curArray = $array[$this->string];
But everytime I run the script I get an error on that line. Can you please tell me why?
The error I get is “Illegal offset type”.
Thanks
It is very likely that
$this->stringisn’t what you think it is. This error is caused by a non string or number being used as an array key.if you do
var_dump($this->string);You should be able to see what the value actually is.Edit:
A
SimpleXMLElementis an object and therefore can’t be used as an array key. You can cast it to a string like so: