listData array

how can i do this




CHtml::listData($arr, '?', '?')

i want get

i think you need a dropDownList




CHtml::dropDownList("Goods[fileName]", "", $arr, array ( ))

i know about dropDownList, also i knew about $arr[‘a’]=‘a’;

lol do you think i don’t know about dropDownList?

i want solution without duplicate keys

You don’t have to use CListData if you have already an array ready.

ClistData is an helper for transform an array of models in an array of key-value pairs for dropDownList.

If you want a dropdownlist you can simply do as said ahmed, if you are working with active records use, for example:

CHtml::dropDownList("Goods[fileName]", "", CHtml::listData($arrayOfModels, 'primaryKey','primaryKey' ))) 

but i don’t work with array of models, i work with one dimention array. and i don’t want to make it two dimention with duplicate keys

so i need some solution to do it

I didn’t get it…

CHtml.activeDropDownList() 3rd argument is an array of pairs value=>display, so if you want to generate a list using this method you have to pass the following array:




But if you just don’t like this syntax, you can try the following:

$data = array('a', 'b', 'c');

CHtml::activeDropDownList($model, 'fileName', array_combine(array_values($data), $data));

oh these useful php functions :D

ok, so i see there no nice solution for this

so will make array with duplicate keys $arr[‘a’]=‘a’;

i have array


so i want it in


so i can i achieve this is there any way. Thank you

Don’t judge about existence of a thing by absence of answers regarding this thing :slight_smile:

Here is a solution for you (for PHP 5.3+):




CHtml::listData($arr, function($model){ return $model; }, function($model){ return $model; });

Your array is already in the suitable form for





Thank you, this is what i need :D