> For the complete documentation index, see [llms.txt](https://minwork.gitbook.io/array/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://minwork.gitbook.io/array/traversing-array/finding.md).

# Finding

## find

#### Definition

```php
Arr::find(array|Iterator|IteratorAggregate $array, callable $condition, string $return = self::FIND_RETURN_VALUE): mixed|mixed[]
```

#### Description

Find array (or iterable object) element(s) that match specified condition.

#### Modes (`$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 |

#### Examples

```php
$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
]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://minwork.gitbook.io/array/traversing-array/finding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
