Answer the question
In order to leave comments, you need to log in
How to access array element in yii2 array?
Good day!
When I select one record:
$date = Statprice::find()->select(['from_date', 'to_date'])->where(['city' => 'Город'])->all();
$date->from_date;
$date = Statprice::find()->select(['from_date', 'to_date'])->where(['city' => 'Город'])->all();
$date->from_date;
Answer the question
In order to leave comments, you need to log in
it's not entirely clear what you want to do when you select one record you get an OBJECT when you select all records you get an ARRAY OF OBJECTS, with which you can work like with a regular array - process in a loop, or for example access by index $date[0]-> from_date. Describe the task more specifically - what do you plan to do with this array, etc.
If memory serves, then in your case you need to get the data as an array.
You can select from_date of all records using the ArrayHelper helper, it has a column () method
It's hard to understand what you want. But apparently this:
$arr = Statprice::find()->all();
$from_date_collumn = ArrayHelper::getColumn($arr, 'from_date')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question