https://github.com/oliver-dvorski/array_find
array_find for php. It stops the linear search when the first match is found.
https://github.com/oliver-dvorski/array_find
arrays linear-search-algorithm php search
Last synced: 3 months ago
JSON representation
array_find for php. It stops the linear search when the first match is found.
- Host: GitHub
- URL: https://github.com/oliver-dvorski/array_find
- Owner: oliver-dvorski
- License: mit
- Created: 2023-03-16T08:46:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-25T11:48:55.000Z (about 1 year ago)
- Last Synced: 2025-11-27T15:37:47.535Z (4 months ago)
- Topics: arrays, linear-search-algorithm, php, search
- Language: PHP
- Homepage: https://packagist.org/packages/oliver-dvorski/array_find
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
ℹ️ As of php 8.4, this function is [natively supported by php](https://www.php.net/manual/en/function.array-find.php).
Install the dependencies with `composer install`.
You can confirm that the program does what it should by running the `composer
test` script.
## Usage
```php
$people = [
['name' => 'John', 'age' => 20],
['name' => 'Jane', 'age' => 21],
['name' => 'Jack', 'age' => 22],
];
// Returns ['name' => 'Jane', 'age' => 21]
$found = array_find($people, fn($item) => $item['name'] === 'Jane');
```