Is there any method like the array_unique for objects? I have a bunch of arrays with ‘Role’ objects that I merge, and then I want to take out the duplicates 🙂
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well,
array_unique()compares the string value of the elements:So make sure to implement the
__toString()method in your class and that it outputs the same value for equal roles, e.g.This would consider two roles as equal if they have the same name.