Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleXMLElement and Warning: Illegal offset type

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?

like image 449
Mostafa Elkady Avatar asked Jun 21 '26 11:06

Mostafa Elkady


1 Answers

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

like image 199
cweiske Avatar answered Jun 23 '26 02:06

cweiske