Skip to content

[12.x] Add Arr::sole() method #55070

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
Mar 18, 2025
Merged

Conversation

ralphjsmit
Copy link
Contributor

I was missing an Arr::sole() method when I was working with a simple array for which wrapping in a collection is quite overkill. This PR adds the method, both a simple version without parameters and a version with a callback support same as the other Arr::where() method.

$foo = Arr::sole(['foo']);

$bar = Arr::sole(['bar', 'baz'], fn (string $value) => $value === 'bar');

Thanks!

ralphjsmit and others added 4 commits March 18, 2025 17:30

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@taylorotwell taylorotwell merged commit e9ce376 into laravel:12.x Mar 18, 2025
33 checks passed
@SteveEdson
Copy link

Ok, this is my new favourite thing in Laravel.

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

3 participants