phpyiiyii1.x

arrays in foreach in yii 1


I have following code in my controller:

 $data= Yii::app()->db->createCommand()
                    ->select('region_id')
                    ->from('user_rights')
                    ->where('user_group_id='.$findRegion['user_group_id'])
                    ->queryAll();

 foreach($data as $key=>$value){
            $array_o[$key] = $value;
        }

var_dump($array_o); returns following value:

array(2) { [0]=> array(1) { ["region_id"]=> string(4) "1703" } [1]=> array(1) { ["region_id"]=> string(4) "1706" } }

But, I need to get similar to following value:

array(2) { [0]=> string(4) "1703" [1]=> string(4) "1706" }.

How can I do it?


Solution

  • Just set the proper value right from the beginning:

    foreach ($data as $key => $value){
        $array_o[$key] = $value['region_id'];
    }