How to access an array inside an object?

2

How to access an array inside an object?

$user = $pdo->query("SELECT * from users LIMIT 1")->fetch(PDO::FETCH_OBJ);

stdClass::__set_state(array(
   'id' => '104',
   'name' => 'John',
   'sex' => 'male',
   'car' => 'Toyota',
))
    
asked by anonymous 21.12.2017 / 21:51

1 answer

1

To access an array inside an object , simply pass the index through keys.

$user->{'0'}->id
$user->{'0'}->name
$user->{'0'}->sex
$user->{'0'}->car
    
21.12.2017 / 22:12