There is an array ($ client) of objects that contains one object:

Array ( [0] => app\models\Client Object ( [_attributes:yii\db\BaseActiveRecord:private] => Array ( [id] => 1 [Name] => Макс [Fam] => Спивак [Och] => Вал ) [_oldAttributes:yii\db\BaseActiveRecord:private] => Array ( [id] => 1 [Name] => Макс [Fam] => Спивак [Och] => Вал ) [_related:yii\db\BaseActiveRecord:private] => Array ( ) [_relationsDependencies:yii\db\BaseActiveRecord:private] => Array ( ) [_errors:yii\base\Model:private] => [_validators:yii\base\Model:private] => [_scenario:yii\base\Model:private] => default [_events:yii\base\Component:private] => Array ( ) [_eventWildcards:yii\base\Component:private] => Array ( ) [_behaviors:yii\base\Component:private] => Array ( ) ) ) 

How to access, for example, id using records like

 $client->{'0'}->id; $client->{0}->id; $client->id; $client->['0']->id 

    2 answers 2

    A little weird question. How do we get the array element? $arr[0] , and how do we get the property of the object? $obj->property .

    What is the conclusion? $obj = $arr[0] , received an object from an array element. $obj->id got the property.

        foreach ($obj as $key => value){ echo $key . ":" . $value->id; }