0

I have following code in my controller in my yii 1application:

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

var_dump($data) returns following result:

array(2) { [0]=> array(1) { ["user_group_id"]=> string(1) "1" } [1]=> array(1) { ["user_group_id"]=> string(1) "3" } } 

How can I convert this array result into string

2 Answers 2

1

Simple display one per one:

foreach($data as $item) {
   echo $item['user_group_id'];
}

Fetch to one string (like @Ripper mentioned):

implode(',', array_column($data, 'user_group_id'));

It depends on what u want to do with this results. Please describe it so we can provide best solution.

Sign up to request clarification or add additional context in comments.

Comments

1

Just use implode combined with array_column as

imlpode(',', array_column($data, 'user_group_id'));

1 Comment

implode() won't work here, cause it array of arrays.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.