Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Array Laravel Package

minwork/array

Minwork Array provides fast, well-tested helpers for nested, associative, and object arrays. Get/set/has plus map, filter, find, group, sort, and validation, with fluent-style chaining. No dependencies; modern PHP syntax.

View on GitHub
Deep Wiki
Context7

check

Definition

{% code title="" %}

Arr::check(array $array, mixed|callable $condition, int $flag = 0): bool

{% endcode %}

Description

Check if some or every array element meets specified condition.

If CHECK_SOME flag is NOT present then every array element must meet specified condition in order to pass check.

Condition

Can be used as stand alone (i.e.Arr::CHECK_STRICT) as well as in conjunction (i.e. Arr::CHECK_STRICT | Arr::CHECK_SOME)

{% hint style="info" %} $flag argument used to be a boolean parameter called $strict

But do not worry, it it is fully backward compatible due to in-flight type conversion from bool to int {% endhint %}

$array = [1, '1', true];

// Every array element is EQUAL to 1 ($value == '1')
Arr::check($array, '1') -> true

// Only one array element is the SAME as 1 ($value === '1') which is not sufficient
Arr::check($array, '1', Arr::CHECK_STRICT) -> false

// When CHECK_SOME flag is present, one element is sufficient to pass check
Arr::check($array, '1', Arr::CHECK_STRICT | Arr::CHECK_SOME) -> true

// You can also use built-in functions to validate whole array
Arr::check($array, 'is_int') -> false
Arr::check($array, 'is_string') -> false

// When CHECK_SOME flag is present only one element need to meet specified condition
Arr::check($array, 'is_int', Arr::CHECK_SOME) -> true
Arr::check($array, 'is_string', Arr::CHECK_SOME) -> true

// Every value of array is truthy
Arr::check($array, function ($value) { return $value; }) -> true
// Above check can be simplified to
Arr::check($array, true) -> true
// Or even shorter
Arr::check($array, 1) -> true

// When CHECK_STRICT flag is present, check will fail for callback return values other true
Arr::check($array, function ($value) { return $value; }, Arr::CHECK_STRICT) -> false
// But when callback is written as follows check will pass
Arr::check($array, function ($value) { return boolval($value); }, Arr::CHECK_STRICT) -> true
// Above check will pass if we add CHECK_SOME flag cause of of the elements is exactly true
Arr::check($array, function ($value) { return $value; }, Arr::CHECK_STRICT | Arr::CHECK_SOME) -> true


// Callback function arguments count is automatically detected
Arr::check($array, function ($value, $key) { return $value > $key; }) -> false
// First array element 1 is greater than its key 0
Arr::check($array, function ($value, $key) { return $value > $key; }, Arr::CHECK_SOME) -> true
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings