Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique() method #371

Open
ahmedghanem00 opened this issue May 16, 2023 · 1 comment
Open

Add unique() method #371

ahmedghanem00 opened this issue May 16, 2023 · 1 comment

Comments

@ahmedghanem00
Copy link

Hi there,

I was in need to filter out the duplicate values from an ArrayCollection, but I couldn't find a method to do that. So I had to use array_unique($collection->toArray()) to get the job done.

Is there any reason to not add an unique() method to do such filtering ?

Thanks

@DouweGnodde
Copy link

DouweGnodde commented Feb 6, 2024

Yes!
This would suffice:

public function unique()
{
    return $this->createFrom(array_values(array_unique($this->toArray())));
}
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants