2
How to access an array within 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',
))
2
How to access an array within 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',
))
1
To access an array within an object, just pass the index through keys.
$user->{'0'}->id
$user->{'0'}->name
$user->{'0'}->sex
$user->{'0'}->car
That’s right chaves
and not colchetes
:D
@dvd grateful for the fix. Ended up going through beaten.
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
I recommend you use
->fetchObject()
. Simpler.– user45722
Tried to sumplesmente
$arraydeobjetos[$indice]->propriedade
? ex:$user[0]->name;
– Bacco