I'm trying to access values from a PHP object returned from an API. I am trying to get the 'total' atribute.
stdClass Object
(
[@attributes] => stdClass Object
(
[status] => ok
)
[invoices] => stdClass Object
(
[@attributes] => stdClass Object
(
[page] => 1
[per_page] => 25
[pages] => 1
[total] => 5
)
My returned object is stored in a variable called $list.
$list->invoices->attributes->total
I'm trying to echo / print_r that, but getting nothing?
Any help is appreciated!
The @
is a part of the property name, you can't just ignore it.
echo $list->invoices->{'@attributes'}->total;
$total = $list->invoices->attributes()->total;
As it turns out, you don't need to even specify @attributes to read this data. The key trick to get to it is to cast the result as a string.
So, I know it seems strange, but this will work in this case:
echo (string)$list->invoices['total'];
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