SimpleXMLElement and Warning: Illegal offset type

余生长醉 提交于 2020-01-04 04:29:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/5166680/simplexmlelement-and-warning-illegal-offset-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!