0

I am doing project in Laravel. Given below is my output array

Array ( [0] => Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => stdClass Object ( [u_id] => f2772366-4e7f-4257-90bd-8ea506dd8f84 ) 1 => stdClass Object ( [u_id] => c0b6da0f-1268-4c0d-a38c-675cc33573a8 ) [2] => stdClass Object ( [u_id] => 15a31589-bba6-4e22-a5c2-1dcd13f43cfe ) [3] => stdClass Object ( [u_id] => a4a05a47-edfe-4f00-aeca-4607897ec760 ) [4] => stdClass Object ( [u_id] => f8b20d31-ac80-4a98-b561-d255c79236fd ) [5] => stdClass Object ( [u_id] => 3901ee9e-01bb-483a-9f74-8f7b76290cd5 ) ) [escapeWhenCastingToString:protected] => ) 1 => Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => stdClass Object ( [u_id] => 15a31589-bba6-4e22-a5c2-1dcd13f43cfe ) 1 => stdClass Object ( [u_id] => 3901ee9e-01bb-483a-9f74-8f7b76290cd5 ) ) [escapeWhenCastingToString:protected] => ) )

I need to print u_id separated by comma

This is what I have done. showing error

foreach($selectedUsers as $key => $selectedUser){
            $listUser[] = $selectedUser->u_id;
        }

On dd() output like thisenter image description here

5

1 Answer 1

0

After

foreach($selectedUsers as $key => $selectedUser){
        $listUser[] = $selectedUser->u_id;
    }

this foreach, you had an array in the$listUser variable. You can use implode() function to merge them with commas. For eg:

$arr = ['a', 'b', 'c'];
$temp = implode(",", $arr);
echo $temp;

which will give a string a,b,c you can see mode details about implode here

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

1 Comment

The asker already stated in their question that foreach($selectedUsers as $key => $selectedUser){ $listUser[] = $selectedUser->u_id; } is "showing error". This means that your answer cannot possibly work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.