How can i loop into the below php object and pull propery value (name, surname, city, country) if a certain property value (id) is given by me.
$users = (object) array( 'id' => '753', 'firstname' => 'trevor', 'lastname' => 'bean', 'address' => array( (object) array( 'country' => 'Romania' 'city' => 'Iasi' ) ) ) (object) array( 'id' => '754', 'firstname' => 'ben', 'lastname' => 'stone', 'address' => array( (object) array( 'country' => 'Hungary' 'city' => 'Budapest' ) ) ); I have tested:
foreach ($users as $user1) { if ($user1->id=== '754') { echo $user1->firstname break; } } And it returns trevor - the firstname of id 753 instead of the firstname ben of the requested id 754