20 public static function lookup($lookupValue, $lookupVector, $resultVector = null)
24 if (!is_array($lookupVector)) {
27 $hasResultVector = isset($resultVector);
28 $lookupRows = self::rowCount($lookupVector);
29 $lookupColumns = self::columnCount($lookupVector);
31 if (($lookupRows === 1 && $lookupColumns > 1) || (!$hasResultVector && $lookupRows === 2 && $lookupColumns !== 2)) {
33 $lookupRows = self::rowCount($lookupVector);
34 $lookupColumns = self::columnCount($lookupVector);
37 $resultVector = self::verifyResultVector($lookupVector, $resultVector);
39 if ($lookupRows === 2 && !$hasResultVector) {
40 $resultVector = array_pop($lookupVector);
41 $lookupVector = array_shift($lookupVector);
44 if ($lookupColumns !== 2) {
45 $lookupVector = self::verifyLookupValues($lookupVector, $resultVector);
53 foreach ($lookupVector as &$value) {
54 if (is_array($value)) {
55 $k = array_keys($value);
56 $key1 = $key2 = array_shift($k);
58 $dataValue1 = $value[$key1];
65 $dataValue2 = array_shift($resultVector);
66 if (is_array($dataValue2)) {
67 $dataValue2 = array_shift($dataValue2);
69 $value = [$key1 => $dataValue1, $key2 => $dataValue2];
78 if ($resultVector === null) {
79 $resultVector = $lookupVector;
82 $resultRows = self::rowCount($resultVector);
83 $resultColumns = self::columnCount($resultVector);
86 if ($resultRows === 1 && $resultColumns > 1) {
93 private static function rowCount(array $dataArray): int
95 return count($dataArray);
100 $rowKeys = array_keys($dataArray);
101 $row = array_shift($rowKeys);
103 return count($dataArray[
$row]);
static lookup($lookupValue, $lookupVector, $resultVector=null)
LOOKUP The LOOKUP function searches for value either from a one-row or one-column range or from an ar...
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 rowCount(array $dataArray)
static transpose($matrixData)
TRANSPOSE.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static verifyResultVector(array $lookupVector, $resultVector)
static verifyLookupValues(array $lookupVector, array $resultVector)
static columnCount(array $dataArray)