Documentation

XLookup extends LookupBase
in package

Table of Contents

Methods

lookup()  : mixed
XLOOKUP — PHP emulation of Excel's XLOOKUP function.
checkMatch()  : int|null
validateIndexLookup()  : int
validateLookupArray()  : void
compareValues()  : int
Compare two values with type coercion matching Excel's behaviour: numbers < strings < booleans
searchBinary()  : int|null
Binary search (searchMode 2 and -2) Assumes array is sorted ascending (searchMode 2) or descending (searchMode -2).
searchLinear()  : int|null
Linear search (searchMode 1 and -1).
wildcardMatch()  : bool
Wildcard match (matchMode 2) Supports Excel wildcards: * (any sequence), ? (any single char), ~ (escape).

Methods

lookup()

XLOOKUP — PHP emulation of Excel's XLOOKUP function.

public static lookup(mixed $lookupValue, mixed $lookupArray, mixed $returnArray[, mixed $ifNotFound = '#N/A!' ][, mixed $matchMode = 0 ][, mixed $searchMode = 1 ]) : mixed
Parameters
$lookupValue : mixed

Value to search for

$lookupArray : mixed

Expect array, Array to search in

$returnArray : mixed

Expect array, Array to return from (must match lookupArray size)

$ifNotFound : mixed = '#N/A!'

Value to return if no match found (default: #N/A!)

$matchMode : mixed = 0

expect int 0 = exact match (default) -1 = exact or next smaller 1 = exact or next larger 2 = wildcard match (* ? ~)

$searchMode : mixed = 1

expect int 1 = first to last (default) -1 = last to first 2 = binary search ascending -2 = binary search descending

checkMatch()

protected static checkMatch(bool $bothNumeric, bool $bothNotNumeric, bool $notExactMatch, int $rowKey, string $cellDataLower, string $lookupLower, int|null $rowNumber) : int|null
Parameters
$bothNumeric : bool
$bothNotNumeric : bool
$notExactMatch : bool
$rowKey : int
$cellDataLower : string
$lookupLower : string
$rowNumber : int|null
Return values
int|null

validateIndexLookup()

protected static validateIndexLookup(array<string|int, mixed> $lookupArray, float|int|string $index_number) : int
Parameters
$lookupArray : array<string|int, mixed>
$index_number : float|int|string

number >= 1

Return values
int

validateLookupArray()

protected static validateLookupArray(mixed $lookupArray) : void
Parameters
$lookupArray : mixed

compareValues()

Compare two values with type coercion matching Excel's behaviour: numbers < strings < booleans

private static compareValues(mixed $a, mixed $b) : int
Parameters
$a : mixed
$b : mixed
Return values
int

searchBinary()

Binary search (searchMode 2 and -2) Assumes array is sorted ascending (searchMode 2) or descending (searchMode -2).

private static searchBinary(mixed $lookupValue, array<string|int, mixed> $lookupArray, int $matchMode, bool $ascending) : int|null
Parameters
$lookupValue : mixed
$lookupArray : array<string|int, mixed>
$matchMode : int
$ascending : bool
Return values
int|null

searchLinear()

Linear search (searchMode 1 and -1).

private static searchLinear(mixed $lookupValue, array<string|int, mixed> $lookupArray, int $matchMode, bool $reverse) : int|null
Parameters
$lookupValue : mixed
$lookupArray : array<string|int, mixed>
$matchMode : int
$reverse : bool
Return values
int|null

wildcardMatch()

Wildcard match (matchMode 2) Supports Excel wildcards: * (any sequence), ? (any single char), ~ (escape).

private static wildcardMatch(string $pattern, string $subject) : bool
Parameters
$pattern : string
$subject : string
Return values
bool

        
On this page

Search results