PHPackages                             baygin/php-search-algorithms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. baygin/php-search-algorithms

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

baygin/php-search-algorithms
============================

The search algorithms implementation for the php arrays that usable as a composer package

1.1.0(3y ago)06GPL-3.0-or-laterPHPPHP &gt;=8.2

Since Apr 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/baygin/php-search-algorithms)[ Packagist](https://packagist.org/packages/baygin/php-search-algorithms)[ RSS](/packages/baygin-php-search-algorithms/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

The Search Algorithms Implementation in PHP 8
=============================================

[](#the-search-algorithms-implementation-in-php-8)

The search algorithm implementation in PHP 8 to find the value with the query as fast.

Usage
=====

[](#usage)

Install
-------

[](#install)

### Git Clone

[](#git-clone)

```
git clone https://github.com/baygin/php-search-algorithms.git
```

### Composer

[](#composer)

```
composer require baygin/php-search-algorithms
```

Binary Search
-------------

[](#binary-search)

### Array

[](#array)

```
$array = [];

for ($index = 0; $index < 100 * 10000; $index++) {
    $array[] = $index + 1;
}

$search = new BinarySearch();

$search->setCompareCallback(fn ($current, $searchValue) => $current === $searchValue)
    ->setDirectionCallback(fn ($current, $searchValue) => $current < $searchValue)
    ->setArray($array)
    ->setSearchValue(98589)
    ->search();

$foundIndex = $search->getFoundIndex();
$foundValue = $search->getFoundValue();
```

### Arrays in array

[](#arrays-in-array)

```
$array = [];

for ($index = 0; $index < 100 * 10000; $index++) {
    $array[] = [
        "id" => $index + 1,
        "first" => "Baris {$index}",
        "last" => "Manco {$index}",
    ];
}

$search = new BinarySearch();

$search->setCompareCallback(fn ($current, $searchValue) => $current["id"] === $searchValue)
    ->setDirectionCallback(fn ($current, $searchValue) => $current["id"] < $searchValue)
    ->setArray($array)
    ->setSearchValue(81300)
    ->search();

$foundIndex = $search->getFoundIndex();
$foundValue = $search->getFoundValue();
```

### Objects in array

[](#objects-in-array)

```
$array = [];

for ($index = 0; $index < 100 * 10000; $index++) {
    $array[] = (object) [
        "id" => $index + 1,
        "first" => "Baris {$index}",
        "last" => "Manco {$index}",
    ];
}

$search = new BinarySearch();
$search->setCompareCallback(fn ($current, $searchValue) => $current->id === $searchValue)
    ->setDirectionCallback(fn ($current, $searchValue) => $current->id < $searchValue)
    ->setArray($array)
    ->setSearchValue(81300)
    ->search();

$foundIndex = $search->getFoundIndex();
$foundValue = $search->getFoundValue();
```

Tests
-----

[](#tests)

```
composer test
```

Contributing
------------

[](#contributing)

If you want to contribute to the development of this library, you can open an issue or submit a pull request.

License
=======

[](#license)

Licensed under the GPL3. See [ LICENSE ](https://github.com/baygin/php-search-algorithms/blob/master/LICENSE) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

2

Last Release

1114d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a7163a1f6c0b257400d77ec4d7f72b753f5dc6d36dc30dec8f9099601288aaa?d=identicon)[baygin](/maintainers/baygin)

---

Top Contributors

[![baygin](https://avatars.githubusercontent.com/u/34795266?v=4)](https://github.com/baygin "baygin (9 commits)")

---

Tags

phparraybinary searchSearch algorithm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/baygin-php-search-algorithms/health.svg)

```
[![Health](https://phpackages.com/badges/baygin-php-search-algorithms/health.svg)](https://phpackages.com/packages/baygin-php-search-algorithms)
```

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
