Implementation of using AR to directly output one-dimensional array in A Bei job / Yii

I haven"t given an AR assignment for a long time. Today we"ll take a look at my needs.

there is a datasheet, user (id, username and created_at, with a total of 4 records. This is required for the job. Use AR to achieve the following results:

An one-dimensional array whose key is user"s id, array and value"s user"s username, is similar to the following result

[
    1=>"abei",
    2=>"abei2017",
    11=>"abei2018"
]

remember, only use AR, without resorting to other class libraries, such as Helper::map

Mar.28,2021

php built-in array: array_column ()


yii's built-in indexBy and column methods are used to implement the requirements in the problem.

  https://nai8.me/article/detai.

Menu