Skip to content

[11.x] Feature: Array reject #54638

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

Merged
merged 4 commits into from
Feb 17, 2025

Conversation

liamduckett
Copy link
Contributor

Hey, this PR adds a reject method to the Array helper.

This will allow users to simplify array filtering code like so:

// Declare array
$array = ['Liam Duckett', 'Liam Doe', 'John Doe', 'John Liam'];

// -- Previously --
$liams = Arr::where($array, fn($value) => str_contains($value, 'Liam'));
$notLiams = Arr::where($array, fn($value) => ! str_contains($value, 'Liam'));

// -- With this PR --
$liams = Arr::where($array, fn($value) => str_contains($value, 'Liam'));
$notLiams = Arr::reject($array, fn($value) => str_contains($value, 'Liam'));

This also brings it more aligned with Collections which already have a reject method. I also thought about adding an alias filter for the where method, but decided this was better done in another PR (thoughts welcome)?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@liamduckett liamduckett changed the title Feature/array reject [11.x] Feature: Array reject Feb 16, 2025
@taylorotwell taylorotwell merged commit 5e5bc04 into laravel:11.x Feb 17, 2025
21 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants