Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

satheeshkumarj's avatar

Print Value From Loop

This 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] => ) [2] => Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => stdClass Object ( [u_id] => 3901ee9e-01bb-483a-9f74-8f7b76290cd5 ) ) [escapeWhenCastingToString:protected] => ) )

Need to print u_id seperated by comma

0 likes
1 reply
SilenceBringer's avatar
Level 55

@satheeshkumarj so you have array of collections. to map collection you need to do

$collection->map(fn ($item) => $item->u_id)

to process whole array

$uIds = collect($array)->flatten(1)
	->map(fn ($item) => $item->u_id)
	->unique()

and to print it

echo $uIds->implode(', ');
1 like

Please or to participate in this conversation.