简体   繁体   中英

Return values by Yii db

I have a following return value from Yii framework query, using the methods and classes built in Yii:

Array
(
    [0] => Array
        (
            [id] => 1
            [title] => Developer
        )

    [1] => Array
        (
            [id] => 2
            [title] => Tester
        )

)

I would like to (using nothing but Yii), rearange this like:

Array
(
    [1] => Developer
    [2] => Tester

)

Meaning, I will not group the results in a specific index of the array, and I will enlist them all in one array, AND my key/indexes will represent the value of ID field from my table, and value of those keys will be values from my "role" field from my table.

Is this possible and how?

You can use the following method, defined here :

CHtml::listData($yourArray, 'id', 'title');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM