Skip to content

[12.x] Introducing Arr::hasAll #55815

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

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from

Conversation

devajmeireles
Copy link
Contributor

@devajmeireles devajmeireles commented May 22, 2025

Continuation of #55770, #26543


Previously, I made a new attempt to introduce hasAll due to frequent needs, but for the wrong target, Collections. Following PR #55770 I am now targeting the correct place, the Arr helper.

Example

use Illuminate\Support\Arr;

$array = ['name' => 'Taylor', 'language' => 'php'];

Arr::hasAll($array, ['name']); // ✅
Arr::hasAll($array, ['name', 'language']); // ✅
Arr::hasAll($array, ['name', 'ide']); // ❌, $array does not have all these keys

Although there are manual ways - PHP only, to achieve the same result without relying on the Arr helper, this brings benefits to framework users in favor of having a helper ready to use, without relying on framework macros or PHP codes written when necessary.

Behind the scenes, we ensure that we use the native has, so that dot notation is fully supported in it.

Co-authored-by: Muhammad Rizky Rizaldi  <[email protected]>
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.

2 participants