[SOLVED] array ?

i have this code:




    $data = GeTCiud::find()

    ->asArray()

    ->all();



code that generates multiple arrays:




Array ( [0] => Array ( [ciud_codi] => 1 [ciud_dane] => 5001 [ciud_nomb] => MEDELLIN [ciud_dist] => ANTIOQUIA [pais_iso3] => COL ) [1] => Array ( [ciud_codi] => 2 [ciud_dane] => 5002 [ciud_nomb] => ABEJORRAL [ciud_dist] => ANTIOQUIA [pais_iso3] => COL )


Array ( [0] => Array ( [id] => 0000  [name] => xxxx [other_field1] => yyyyy [other_field2] => zzzz ))



but I need only generate me an array that itself contains the id and name :





Array ( [id1] => name [id2] => name2 )



someone can help me

If you use keys as "id1", "id2, "id…", how you list them ?

Check out indexBy()

guys I need to generate an associative array ( key=>value ) from my tb_ciuds any have 1 example for me pls

You can use the map() function :




$data = GeTCiud::find()

    ->asArray()

    ->all();

$niceData = yii\helpers\ArrayHelper::map($data, 'id', 'name');



This function is usefule for dropdownList function ;)

thx buddy this is just what I needed! :D