开发者

SimpleXMLElement and Warning: Illegal offset type

开发者 https://www.devze.com 2023-02-14 20:26 出处:网络
Warning: Illegal offset type i have this var from an xml output var_dump($key); its give me object(SimpleXMLElement)#11 (1) { [0]=> string开发者_运维技巧(5) \"Cairo\" }

Warning: Illegal offset type

i have this var from an xml output

var_dump($key);

its give me

object(SimpleXMLElement)#11 (1) { [0]=> string开发者_运维技巧(5) "Cairo" } 

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

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

the error appear when do this

echo $lang[$key];

and its give me the "Warning: Illegal offset type" because of the key is SimpleXMLElement how i can make it normal var?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消