php - Im trying to loop using foreach and use the method array_push() -


i trying loop , got following error:

array_push() expects parameter 1 array, object given

my controller:

public function viewsponsorinfo($sponsor_id) {     $id = $sponsor_id;     $user_id = user::where('id','=',$id)->get();     $user_roles = [];     foreach ($user_id $id) {         array_push($user_id, $id->role);     } } 

you have $user_roles , $user_id mixed in array push.

change:

array_push($user_id, $id->role); 

to:

array_push($user_roles, $id->role); 

the first argument array_push array pushing item. you're trying push user_id user object, not array, hence error.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -