20 public static function lookup($lookupValue, $lookupVector, $resultVector =
null)
24 if (!is_array($lookupVector)) {
27 $hasResultVector = isset($resultVector);
31 if (($lookupRows === 1 && $lookupColumns > 1) || (!$hasResultVector && $lookupRows === 2 && $lookupColumns !== 2)) {
39 if ($lookupRows === 2 && !$hasResultVector) {
40 $resultVector = array_pop($lookupVector);
41 $lookupVector = array_shift($lookupVector);
44 if ($lookupColumns !== 2) {
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;
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]);
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 columnCount(array $dataArray)
static verifyResultVector(array $lookupVector, $resultVector)
static rowCount(array $dataArray)
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 verifyLookupValues(array $lookupVector, array $resultVector)
static transpose($matrixData)
TRANSPOSE.
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...