I have some json object that I decoded, and one of the attributes starts with an "@" and I can't access the element with php because it throws an error.
[offers] => stdClass Object
(
[@attributes] => stdClass Object
(
[id] => levaka0B8a
)
)
How would I go about accessing attributes?
You can access it by a string:
echo $obj->{'@attributes'}->id; // levaka0B8a
Or a variable:
$name = '@attributes';
echo $obj->$name->id;
For more information on how variables are defined and used, see the following docs:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With