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',
))
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',
))
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