---
title: "lint/php-8.4/prefer-array-find"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/php-8.4/prefer-array-find" />

In the [`modernize`](/docs/rules/sets/modernize) set. Safe fix. Gated by php-8.4.

## What it does

Replace foreach loops with array_find(), array_find_key(), array_any() or array_all() (PHP 8.4).

## Configuration

```toml title="pun.toml"
[lint.rules]
"php-8.4/prefer-array-find" = "error"
```

To skip it in some files or lines, add an [override](/docs/configuration/pun-toml#lint) or an [ignore comment](/docs/configuration/ignore-comments).

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `functions` | `list` | `array-all`, `array-any`, `array-find`, `array-find-key` | `["array-all", "array-any", "array-find", "array-find-key"]` | None (Pun's own) |

## Replaces

- [`ForeachToArrayAll`](https://getrector.com/rule-detail/foreach-to-array-all-rector) (rector)
- [`ForeachToArrayAny`](https://getrector.com/rule-detail/foreach-to-array-any-rector) (rector)
- [`ForeachToArrayFind`](https://getrector.com/rule-detail/foreach-to-array-find-rector) (rector)
- [`ForeachToArrayFindKey`](https://getrector.com/rule-detail/foreach-to-array-find-key-rector) (rector)

## Merged rules

These old IDs are now this rule. A config that still names one stops with an error. See [merged rules](/docs/migrate/merged-rules).

- `lint/php-8.4/prefer-array-all`
- `lint/php-8.4/prefer-array-any`
- `lint/php-8.4/prefer-array-find-key`

[More lint/php-8.4 rules](/docs/rules/lint/php-8.4) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
