PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] arrays in foreach in yii 1

 March 19, 2022     php, yii, yii1.x     No comments   

Issue

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'];
}


Answered By - Bizley
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing