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.
Arr::find(array|Iterator|IteratorAggregate $array, callable $condition, string $return = self::FIND_RETURN_VALUE): mixed|mixed[]
Find array (or iterable object) element(s) that match specified condition.
$return method argument)| Constant name | Description |
|---|---|
| FIND_RETURN_VALUE | Return first value of an array that match find condition |
| FIND_RETURN_KEY | Return first key of an array that match find condition |
| FIND_RETURN_ALL | Return array of all values (preserving original keys) that match find condition |
$array = [
'a' => 0,
'b' => 1,
3 => 'c',
4 => 5
];
Arr::find($array, 'boolval') -> 1
Arr::find($array, function ($element) {
return is_string($element);
}) -> 'c'
Arr::find($array, 'boolval', Arr::FIND_RETURN_KEY) -> 'b'
Arr::find($array, function ($element) {
return is_string($element);
}, Arr::FIND_RETURN_KEY) -> 3
Arr::find($array, 'boolval', Arr::FIND_RETURN_ALL) ->
[
'b' => 1,
3 => 'c',
4 => 5
]
Arr::find($array, function ($element) {
return is_string($element);
}, Arr::FIND_RETURN_ALL) ->
[
3 => 'c',
]
Arr::find($array, function ($element) {
return is_number($element);
}, Arr::FIND_RETURN_ALL) ->
[
'a' => 0,
'b' => 1,
4 => 5
]
How can I help you explore Laravel packages today?