I have an object that comes from a class on PHP which I load in an array like this:
$result2 = json_decode($etsyService->request('/receipts/12121212'));
When I print_r the array $result2, I get:
stdClass Object
(
[count] => 1
[results] => Array
(
[0] => stdClass Object
(
[receipt_id] => 1212121212
[order_id] => 1111111
[seller_user_id] => 2525252
[buyer_user_id] => ABCD
[creation_tsz] => 0000000
My question is, how can I echo one of these fields individually? For example just echo the seller_user_id (i.e. 2525252).
The result is an object containing an array of objects. Use -> for object properties and [k] for array elements:
echo $result2->results[0]->seller_user_id
Try:
echo $result2->results[0]->seller_user_id;
With -> you access the object and then with [] you can access the array.
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