How to access an object with a hash symbol in the key name?

How do you access a PHP c # object in the name of $ key?

Example:

 [image] => stdClass Object ( [#text] => http://userserve-ak.last.fm/serve/_/85003/Red+Hot+Chili+Peppers.jpg [name] => original [width] => 937 [height] => 1276 ) 

I want to access the #text property, but $image->#text does not work, because PHP interprets # as the beginning of the comment.

How to do it?

+4
source share
3 answers

You can try:

 $image->{'#text'} 
+13
source

could be like this: (not sure)

 $image->{"#text"} 
+1
source

One way is to use variable key names:

 $keyname = '#text'; $value = $image->$keyname; 
0
source

All Articles