问题
so I acquired a json object from an API and json decoded it...
but then the returned object is of the following:
stdClass Object
(
[id] => stdClass Object
(
[$t] => some string
)
)
And as you can see there is a property with a $ sign in it
but when I do $object->id->$t
<--that returns error since it thinks $t is a variable
how would I go about fetching that variable with $ sign?
回答1:
Encapsulate it as a single-quoted string:
echo $object->id->{'$t'};
Note that you cannot use double quotes for the same reason you cannot use $object->id->$t
: PHP will attempt to interpolate $t
. However, you could use double quotes if you escape the dollar sign:
echo $obj->id->{"\$t"};
You can see it working in this simple demo.
来源:https://stackoverflow.com/questions/11871872/getting-php-variable-from-an-object-in-which-one-of-its-properties-has-sign