Yii - How to get a values array from an Active Record

前端 未结 9 2600
北荒
北荒 2021-02-15 13:12

Using Yii, how can I get an array from an Active Record.

Say something like this:

array(\'foo\', \'bar\', \'lala\')

From something like thi

9条回答
  •  孤街浪徒
    2021-02-15 13:19

    For yii2 , use:

    yii\helpers\ArrayHelper::map(MyModel::find()->all(), 'id', 'name'));
    

    or

    yii\helpers\ArrayHelper::getColumn(MyModel::find()->all(), 'name'));
    

提交回复
热议问题