M
M
McMike2018-04-06 14:07:25
Yii
McMike, 2018-04-06 14:07:25

How to select an array of values ​​of a certain column from an array of objects?

Let's say I do this:
Account::find()->where(...)->all() - I get an array of objects, each object has a field, for example id. I need a one dimensional array of id's of these objects. Is there a way to pull them out in one line? Maybe some ArrayHelper?
The output should be [1,2,3]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-04-06
@McMike

\yii\helpers\ArrayHelper::getColumn($models, 'id')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question