metaforce
metaforce

Reputation: 1377

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?

Upvotes: 1

Views: 295

Answers (1)

Wytse
Wytse

Reputation: 500

You can use the following method, defined here:

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

Upvotes: 3

Related Questions