echo array on CHtml::listData

hi all,

i’ve got problem on display string value from array value on CHtml::listdata

i want to keep data array on variable, but i try to display array with :

$models = user::model()->findAll(" sex='male' ");

    $tripsArray = CHtml::listData($models, 'name', 'contact');   


        foreach ($tripsArray as $tripsArray) {

              echo $tripsArray."<br>";


and the result just display contact and name was not displayed.

how to display name and contact ?

thanks for advices

This how U wrote:

CHtml::listData($models, ‘name’, ‘contact’);

is generating ‘name’ as value and ‘contact’ like label, that’s why only ‘contact’ is displayed.

Please check :

CHtml::listData($models, ‘name’, ‘contact’);

Seems that I misunderstood U:


    foreach (&#036;tripsArray as &#036;tripsArray) {

          echo &#036;tripsArray.&quot;&lt;br&gt;&quot;;


if U want to display trough foreach:


    foreach (&#036;tripsArray as &#036;key =&gt; &#036;tripArray) {

          echo &#036;key.&#036;tripArray.&quot;&lt;br&gt;&quot;;


since ‘name’ is key and $tripArray is value

1 Like

Thanks dragan.zivkovic,

that’s amazing bro :D

You are wellcome ;)