SimpleXMLElement and warning: invalid offset type

Warning: invalid offset type

I have this var from xml output

var_dump($key);

give it to me

object(SimpleXMLElement)#11 (1) { [0]=> string(5) "Cairo" } 

now I want to make "Cairo" as a key to get its value as

$lang[] = array('Cairo' => "Cairo city");

an error occurs while doing this

echo $lang[$key];

and this will give me "Warning: Illegal offset type" because of the key is SimpleXMLElement how can I make this a regular var?

+3
source share
1 answer

Move it to a string with (string)$key.

+9
source

Source: https://habr.com/ru/post/1795720/


All Articles