24 public static function lookup($lookupValue, $lookupArray, $indexNumber, $notExactMatch =
true)
31 $indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
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']);
49 $rowNumber = self::vLookupSearch($lookupValue, $lookupArray, $firstColumn, $notExactMatch);
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)))
92 $rowNumber = self::checkMatch(
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 vLookupSearch($lookupValue, $lookupArray, $column, $notExactMatch)
static vlookupSort($a, $b)
static strToLower($pValue)
Convert a UTF-8 encoded string to lower case.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.