Skip to content

samsonasik/ArrayLookup

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ArrayLookup

Latest Version ci build Code Coverage PHPStan Downloads

Introduction

ArrayLookup is a fast array lookup library.

Features

  • Search at least times: once(), twice(), times()
  • Search exact times: once(), twice(), times()

Installation

Require this library uses composer.

composer require samsonasik/array-lookup

Usage

A. AtLeast

  1. AtLeast::once()

It verify that data has filtered found item at least once.

$data = [1, 2, 3];
$callable = static fn($datum): bool => $datum === 1;

var_dump(\ArrayLookup\AtLeast::once($data, $callable)) // true
  1. AtLeast::twice()

It verify that data has filtered found item at least twice.

$data = [1, "1", 3];
$callable = static fn($datum): bool => $datum == 1;

var_dump(\ArrayLookup\AtLeast::twice($data, $callable)) // true
  1. AtLeast::times()

It verify that data has filtered found item at least times passed in 3rd arg.

$data = [false, null, 0];
$callable = static fn($datum): bool => ! $datum;
$times = 3;

var_dump(\ArrayLookup\AtLeast::times($data, $callable, $times)) // true

B. Only

  1. Only::once()

It verify that data has filtered found item exactly found only once.

$data = [1, 2, 3];
$callable = static fn($datum): bool => $datum === 1;

var_dump(\ArrayLookup\Only::once($data, $callable)) // true


$data = [1, "1", 3]
$callable = static fn($datum): bool => $datum == 1;

var_dump(\ArrayLookup\Only::once($data, $callable)) // false
  1. Only::twice()

It verify that data has filtered found item exactly found only once.

$data = [1, "1", 3];
$callable = static fn($datum): bool => $datum == 1;

var_dump(\ArrayLookup\Only::twice($data, $callable)) // true

$data = [true, 1, new stdClass()];
$callable = static fn($datum): bool => (bool) $datum;

var_dump(\ArrayLookup\Only::twice($data, $callable)) // false
  1. Only::times()

It verify that data has filtered found item exactly found only same with times passed in 3rd arg.

$data = [false, null, 1];
$callable = static fn($datum): bool => ! $datum;
$times = 2;

var_dump(\ArrayLookup\Only::times($data, $callable, $times)) // true


$data = [false, null, 0];
$callable = static fn($datum): bool => ! $datum;
$times = 2;

var_dump(\ArrayLookup\Only::times($data, $callable, $times)) // false

About

A fast array lookup library

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages