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

前端 未结 9 2557
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 13:19

    You could also do something like

    $countries = Country::model()->findAll();
    array_values(CHtml::listData($countries, 'country_id', 'country_name'));
    

    which returns an array of all country names, or

    array_keys(CHtml::listData($countries, 'country_id', 'country_name'));
    

    which returns an array of all country ids.

提交回复
热议问题