Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display one single value from object array retrieved from a class on PHP

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).

like image 503
user2509541 Avatar asked Feb 05 '26 23:02

user2509541


2 Answers

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
like image 97
helion3 Avatar answered Feb 07 '26 12:02

helion3


Try:

echo $result2->results[0]->seller_user_id;

With -> you access the object and then with [] you can access the array.

like image 36
samyb8 Avatar answered Feb 07 '26 13:02

samyb8