oliver-dvorski/array_find

array_find for php. It stops the linear search when the first match is found.

Maintainers

Package info

github.com/oliver-dvorski/array_find

pkg:composer/oliver-dvorski/array_find

Statistics

Installs: 304

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2023-03-16 09:19 UTC

This package is auto-updated.

Last update: 2026-02-25 13:56:19 UTC


README

ℹ️ As of php 8.4, this function is natively supported by php.

Install the dependencies with composer install.

You can confirm that the program does what it should by running the composer test script.

Usage

$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');