How To Use Arrayhelper?

I want to create a dropdown with items from the database.

My model:

\common\models\Country … i want the ‘id’ field as the value and the ‘name’ field as the option label. How can i accomplish this?

What i tried so far:


$models = \common\models\Country::find()->all();

$data = ArrayHelper::toArray($models, $properties = []);

But i’m not sure how to use $properties in this case. Can someone help me with this?

For example, you can do this


$models = \common\models\Country::find()->asArray()->all();

$data = ArrayHelper::map($models, 'id', 'name')

As you can see, I used new asArray() feature to avoid unnecessary conversion array - object - array.

Thanks man! Works like a charm :)