How to access an array within an object?

Asked

Viewed 48 times

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',
))
  • I recommend you use ->fetchObject(). Simpler.

  • Tried to sumplesmente $arraydeobjetos[$indice]->propriedade ? ex: $user[0]->name;

1 answer

1

  • That’s right chaves and not colchetes :D

  • @dvd grateful for the fix. Ended up going through beaten.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.