开发者

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

开发者 https://www.devze.com 2023-03-09 22:53 出处:网络
How do you access a PHP object that has a # in the $key name? Example: [image] => stdClass Object (

How do you access a PHP object that has a # in the $key name?

Example:

[image] => stdClass Object 
       ( 
  开发者_Python百科     [#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 doesn't work because PHP interprets the # as the start of a comment.

How do I do this?


You can try with:

$image->{'#text'}


maybe like this: (not sure)

$image->{"#text"}


One way is to use variable key names:

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

精彩评论

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