24 public static function lookup($lookupValue, $lookupArray, $indexNumber, $notExactMatch =
true)
33 return $e->getMessage();
36 $f = array_keys($lookupArray);
37 $firstRow = array_pop(
$f);
38 if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray[$firstRow]))) {
41 $columnKeys = array_keys($lookupArray[$firstRow]);
42 $returnColumn = $columnKeys[--$indexNumber];
43 $firstColumn = array_shift($columnKeys);
45 if (!$notExactMatch) {
46 uasort($lookupArray, [
'self',
'vlookupSort']);
51 if ($rowNumber !==
null) {
53 return $lookupArray[$rowNumber][$returnColumn];
62 $firstColumn = key($a);
66 if ($aLower == $bLower) {
70 return ($aLower < $bLower) ? -1 : 1;
73 private static function vLookupSearch($lookupValue, $lookupArray, $column, $notExactMatch)
78 foreach ($lookupArray as $rowKey => $rowData) {
79 $bothNumeric = is_numeric($lookupValue) && is_numeric($rowData[$column]);
80 $bothNotNumeric = !is_numeric($lookupValue) && !is_numeric($rowData[$column]);
86 (($bothNumeric && ($rowData[$column] > $lookupValue)) ||
87 ($bothNotNumeric && ($cellDataLower > $lookupLower)))
An exception for terminatinating execution or to throw for unit testing.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static validateIndexLookup($lookup_array, $index_number)
static checkMatch(bool $bothNumeric, bool $bothNotNumeric, $notExactMatch, int $rowKey, string $cellDataLower, string $lookupLower, ?int $rowNumber)
static vLookupSearch($lookupValue, $lookupArray, $column, $notExactMatch)
static lookup($lookupValue, $lookupArray, $indexNumber, $notExactMatch=true)
VLOOKUP The VLOOKUP function searches for value in the left-most column of lookup_array and returns t...
static vlookupSort($a, $b)
static strToLower($pValue)
Convert a UTF-8 encoded string to lower case.