1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28:
29:
30: if (!defined('PHPEXCEL_ROOT')) {
31: 32: 33:
34: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35: require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36: }
37:
38:
39: 40: 41: 42: 43: 44: 45:
46: class PHPExcel_Calculation_LookupRef {
47:
48:
49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
70: public static function CELL_ADDRESS($row, $column, $relativity=1, $referenceStyle=True, $sheetText='') {
71: $row = PHPExcel_Calculation_Functions::flattenSingleValue($row);
72: $column = PHPExcel_Calculation_Functions::flattenSingleValue($column);
73: $relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity);
74: $sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText);
75:
76: if (($row < 1) || ($column < 1)) {
77: return PHPExcel_Calculation_Functions::VALUE();
78: }
79:
80: if ($sheetText > '') {
81: if (strpos($sheetText,' ') !== False) { $sheetText = "'".$sheetText."'"; }
82: $sheetText .='!';
83: }
84: if ((!is_bool($referenceStyle)) || $referenceStyle) {
85: $rowRelative = $columnRelative = '$';
86: $column = PHPExcel_Cell::stringFromColumnIndex($column-1);
87: if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; }
88: if (($relativity == 3) || ($relativity == 4)) { $rowRelative = ''; }
89: return $sheetText.$columnRelative.$column.$rowRelative.$row;
90: } else {
91: if (($relativity == 2) || ($relativity == 4)) { $column = '['.$column.']'; }
92: if (($relativity == 3) || ($relativity == 4)) { $row = '['.$row.']'; }
93: return $sheetText.'R'.$row.'C'.$column;
94: }
95: }
96:
97:
98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111:
112: public static function COLUMN($cellAddress=Null) {
113: if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
114:
115: if (is_array($cellAddress)) {
116: foreach($cellAddress as $columnKey => $value) {
117: $columnKey = preg_replace('/[^a-z]/i','',$columnKey);
118: return (integer) PHPExcel_Cell::columnIndexFromString($columnKey);
119: }
120: } else {
121: if (strpos($cellAddress,'!') !== false) {
122: list($sheet,$cellAddress) = explode('!',$cellAddress);
123: }
124: if (strpos($cellAddress,':') !== false) {
125: list($startAddress,$endAddress) = explode(':',$cellAddress);
126: $startAddress = preg_replace('/[^a-z]/i','',$startAddress);
127: $endAddress = preg_replace('/[^a-z]/i','',$endAddress);
128: $returnValue = array();
129: do {
130: $returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress);
131: } while ($startAddress++ != $endAddress);
132: return $returnValue;
133: } else {
134: $cellAddress = preg_replace('/[^a-z]/i','',$cellAddress);
135: return (integer) PHPExcel_Cell::columnIndexFromString($cellAddress);
136: }
137: }
138: }
139:
140:
141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151:
152: public static function COLUMNS($cellAddress=Null) {
153: if (is_null($cellAddress) || $cellAddress === '') {
154: return 1;
155: } elseif (!is_array($cellAddress)) {
156: return PHPExcel_Calculation_Functions::VALUE();
157: }
158:
159: $x = array_keys($cellAddress);
160: $x = array_shift($x);
161: $isMatrix = (is_numeric($x));
162: list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
163:
164: if ($isMatrix) {
165: return $rows;
166: } else {
167: return $columns;
168: }
169: }
170:
171:
172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185:
186: public static function ROW($cellAddress=Null) {
187: if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
188:
189: if (is_array($cellAddress)) {
190: foreach($cellAddress as $columnKey => $rowValue) {
191: foreach($rowValue as $rowKey => $cellValue) {
192: return (integer) preg_replace('/[^0-9]/i','',$rowKey);
193: }
194: }
195: } else {
196: if (strpos($cellAddress,'!') !== false) {
197: list($sheet,$cellAddress) = explode('!',$cellAddress);
198: }
199: if (strpos($cellAddress,':') !== false) {
200: list($startAddress,$endAddress) = explode(':',$cellAddress);
201: $startAddress = preg_replace('/[^0-9]/','',$startAddress);
202: $endAddress = preg_replace('/[^0-9]/','',$endAddress);
203: $returnValue = array();
204: do {
205: $returnValue[][] = (integer) $startAddress;
206: } while ($startAddress++ != $endAddress);
207: return $returnValue;
208: } else {
209: list($cellAddress) = explode(':',$cellAddress);
210: return (integer) preg_replace('/[^0-9]/','',$cellAddress);
211: }
212: }
213: }
214:
215:
216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226:
227: public static function ROWS($cellAddress=Null) {
228: if (is_null($cellAddress) || $cellAddress === '') {
229: return 1;
230: } elseif (!is_array($cellAddress)) {
231: return PHPExcel_Calculation_Functions::VALUE();
232: }
233:
234: $i = array_keys($cellAddress);
235: $isMatrix = (is_numeric(array_shift($i)));
236: list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
237:
238: if ($isMatrix) {
239: return $columns;
240: } else {
241: return $rows;
242: }
243: }
244:
245:
246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258:
259: public static function HYPERLINK($linkURL = '', $displayName = null, PHPExcel_Cell $pCell = null) {
260: $args = func_get_args();
261: $pCell = array_pop($args);
262:
263: $linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL);
264: $displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName);
265:
266: if ((!is_object($pCell)) || (trim($linkURL) == '')) {
267: return PHPExcel_Calculation_Functions::REF();
268: }
269:
270: if ((is_object($displayName)) || trim($displayName) == '') {
271: $displayName = $linkURL;
272: }
273:
274: $pCell->getHyperlink()->setUrl($linkURL);
275:
276: return $displayName;
277: }
278:
279:
280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297:
298: public static function INDIRECT($cellAddress = NULL, PHPExcel_Cell $pCell = NULL) {
299: $cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress);
300: if (is_null($cellAddress) || $cellAddress === '') {
301: return PHPExcel_Calculation_Functions::REF();
302: }
303:
304: $cellAddress1 = $cellAddress;
305: $cellAddress2 = NULL;
306: if (strpos($cellAddress,':') !== false) {
307: list($cellAddress1,$cellAddress2) = explode(':',$cellAddress);
308: }
309:
310: if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) ||
311: ((!is_null($cellAddress2)) && (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress2, $matches)))) {
312: if (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $cellAddress1, $matches)) {
313: return PHPExcel_Calculation_Functions::REF();
314: }
315:
316: if (strpos($cellAddress,'!') !== FALSE) {
317: list($sheetName, $cellAddress) = explode('!',$cellAddress);
318: $sheetName = trim($sheetName, "'");
319: $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
320: } else {
321: $pSheet = $pCell->getWorksheet();
322: }
323:
324: return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, FALSE);
325: }
326:
327: if (strpos($cellAddress,'!') !== FALSE) {
328: list($sheetName,$cellAddress) = explode('!',$cellAddress);
329: $sheetName = trim($sheetName, "'");
330: $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
331: } else {
332: $pSheet = $pCell->getWorksheet();
333: }
334:
335: return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, FALSE);
336: }
337:
338:
339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363:
364: public static function OFFSET($cellAddress=Null,$rows=0,$columns=0,$height=null,$width=null) {
365: $rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows);
366: $columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns);
367: $height = PHPExcel_Calculation_Functions::flattenSingleValue($height);
368: $width = PHPExcel_Calculation_Functions::flattenSingleValue($width);
369: if ($cellAddress == Null) {
370: return 0;
371: }
372:
373: $args = func_get_args();
374: $pCell = array_pop($args);
375: if (!is_object($pCell)) {
376: return PHPExcel_Calculation_Functions::REF();
377: }
378:
379: $sheetName = NULL;
380: if (strpos($cellAddress,"!")) {
381: list($sheetName,$cellAddress) = explode("!",$cellAddress);
382: $sheetName = trim($sheetName, "'");
383: }
384: if (strpos($cellAddress,":")) {
385: list($startCell,$endCell) = explode(":",$cellAddress);
386: } else {
387: $startCell = $endCell = $cellAddress;
388: }
389: list($startCellColumn,$startCellRow) = PHPExcel_Cell::coordinateFromString($startCell);
390: list($endCellColumn,$endCellRow) = PHPExcel_Cell::coordinateFromString($endCell);
391:
392: $startCellRow += $rows;
393: $startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1;
394: $startCellColumn += $columns;
395:
396: if (($startCellRow <= 0) || ($startCellColumn < 0)) {
397: return PHPExcel_Calculation_Functions::REF();
398: }
399: $endCellColumn = PHPExcel_Cell::columnIndexFromString($endCellColumn) - 1;
400: if (($width != null) && (!is_object($width))) {
401: $endCellColumn = $startCellColumn + $width - 1;
402: } else {
403: $endCellColumn += $columns;
404: }
405: $startCellColumn = PHPExcel_Cell::stringFromColumnIndex($startCellColumn);
406:
407: if (($height != null) && (!is_object($height))) {
408: $endCellRow = $startCellRow + $height - 1;
409: } else {
410: $endCellRow += $rows;
411: }
412:
413: if (($endCellRow <= 0) || ($endCellColumn < 0)) {
414: return PHPExcel_Calculation_Functions::REF();
415: }
416: $endCellColumn = PHPExcel_Cell::stringFromColumnIndex($endCellColumn);
417:
418: $cellAddress = $startCellColumn.$startCellRow;
419: if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) {
420: $cellAddress .= ':'.$endCellColumn.$endCellRow;
421: }
422:
423: if ($sheetName !== NULL) {
424: $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
425: } else {
426: $pSheet = $pCell->getWorksheet();
427: }
428:
429: return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False);
430: }
431:
432:
433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450:
451: public static function CHOOSE() {
452: $chooseArgs = func_get_args();
453: $chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs));
454: $entryCount = count($chooseArgs) - 1;
455:
456: if(is_array($chosenEntry)) {
457: $chosenEntry = array_shift($chosenEntry);
458: }
459: if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
460: --$chosenEntry;
461: } else {
462: return PHPExcel_Calculation_Functions::VALUE();
463: }
464: $chosenEntry = floor($chosenEntry);
465: if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
466: return PHPExcel_Calculation_Functions::VALUE();
467: }
468:
469: if (is_array($chooseArgs[$chosenEntry])) {
470: return PHPExcel_Calculation_Functions::flattenArray($chooseArgs[$chosenEntry]);
471: } else {
472: return $chooseArgs[$chosenEntry];
473: }
474: }
475:
476:
477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489:
490: public static function MATCH($lookup_value, $lookup_array, $match_type=1) {
491: $lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array);
492: $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
493: $match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type);
494:
495: $lookup_value = strtolower($lookup_value);
496:
497:
498: if ((!is_numeric($lookup_value)) && (!is_string($lookup_value)) && (!is_bool($lookup_value))) {
499: return PHPExcel_Calculation_Functions::NA();
500: }
501:
502:
503: if (($match_type !== 0) && ($match_type !== -1) && ($match_type !== 1)) {
504: return PHPExcel_Calculation_Functions::NA();
505: }
506:
507:
508: $lookupArraySize = count($lookup_array);
509: if ($lookupArraySize <= 0) {
510: return PHPExcel_Calculation_Functions::NA();
511: }
512:
513:
514: foreach($lookup_array as $i => $lookupArrayValue) {
515:
516: if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) &&
517: (!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) {
518: return PHPExcel_Calculation_Functions::NA();
519: }
520:
521: if (is_string($lookupArrayValue)) {
522: $lookup_array[$i] = strtolower($lookupArrayValue);
523: }
524: if ((is_null($lookupArrayValue)) && (($match_type == 1) || ($match_type == -1))) {
525: $lookup_array = array_slice($lookup_array,0,$i-1);
526: }
527: }
528:
529:
530: if ($match_type == 1) {
531: asort($lookup_array);
532: $keySet = array_keys($lookup_array);
533: } elseif($match_type == -1) {
534: arsort($lookup_array);
535: $keySet = array_keys($lookup_array);
536: }
537:
538:
539:
540:
541:
542:
543:
544: foreach($lookup_array as $i => $lookupArrayValue) {
545: if (($match_type == 0) && ($lookupArrayValue == $lookup_value)) {
546:
547: return ++$i;
548: } elseif (($match_type == -1) && ($lookupArrayValue <= $lookup_value)) {
549:
550:
551:
552:
553:
554:
555: $i = array_search($i,$keySet);
556:
557:
558: if ($i < 1){
559:
560: break;
561: } else {
562:
563: return $keySet[$i-1]+1;
564: }
565: } elseif (($match_type == 1) && ($lookupArrayValue >= $lookup_value)) {
566:
567:
568:
569:
570:
571:
572: $i = array_search($i,$keySet);
573:
574:
575: if ($i < 1){
576:
577: break;
578: } else {
579:
580: return $keySet[$i-1]+1;
581: }
582: }
583: }
584:
585:
586: return PHPExcel_Calculation_Functions::NA();
587: }
588:
589:
590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602:
603: public static function INDEX($arrayValues,$rowNum = 0,$columnNum = 0) {
604:
605: if (($rowNum < 0) || ($columnNum < 0)) {
606: return PHPExcel_Calculation_Functions::VALUE();
607: }
608:
609: if (!is_array($arrayValues)) {
610: return PHPExcel_Calculation_Functions::REF();
611: }
612:
613: $rowKeys = array_keys($arrayValues);
614: $columnKeys = @array_keys($arrayValues[$rowKeys[0]]);
615:
616: if ($columnNum > count($columnKeys)) {
617: return PHPExcel_Calculation_Functions::VALUE();
618: } elseif ($columnNum == 0) {
619: if ($rowNum == 0) {
620: return $arrayValues;
621: }
622: $rowNum = $rowKeys[--$rowNum];
623: $returnArray = array();
624: foreach($arrayValues as $arrayColumn) {
625: if (is_array($arrayColumn)) {
626: if (isset($arrayColumn[$rowNum])) {
627: $returnArray[] = $arrayColumn[$rowNum];
628: } else {
629: return $arrayValues[$rowNum];
630: }
631: } else {
632: return $arrayValues[$rowNum];
633: }
634: }
635: return $returnArray;
636: }
637: $columnNum = $columnKeys[--$columnNum];
638: if ($rowNum > count($rowKeys)) {
639: return PHPExcel_Calculation_Functions::VALUE();
640: } elseif ($rowNum == 0) {
641: return $arrayValues[$columnNum];
642: }
643: $rowNum = $rowKeys[--$rowNum];
644:
645: return $arrayValues[$rowNum][$columnNum];
646: }
647:
648:
649: 650: 651: 652: 653: 654: 655: 656:
657: public static function TRANSPOSE($matrixData) {
658: $returnMatrix = array();
659: if (!is_array($matrixData)) { $matrixData = array(array($matrixData)); }
660:
661: $column = 0;
662: foreach($matrixData as $matrixRow) {
663: $row = 0;
664: foreach($matrixRow as $matrixCell) {
665: $returnMatrix[$row][$column] = $matrixCell;
666: ++$row;
667: }
668: ++$column;
669: }
670: return $returnMatrix;
671: }
672:
673:
674: private static function _vlookupSort($a,$b) {
675: $f = array_keys($a);
676: $firstColumn = array_shift($f);
677: if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) {
678: return 0;
679: }
680: return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1;
681: }
682:
683:
684: 685: 686: 687: 688: 689: 690: 691: 692:
693: public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) {
694: $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
695: $index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
696: $not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
697:
698:
699: if ($index_number < 1) {
700: return PHPExcel_Calculation_Functions::VALUE();
701: }
702:
703:
704: if ((!is_array($lookup_array)) || (empty($lookup_array))) {
705: return PHPExcel_Calculation_Functions::REF();
706: } else {
707: $f = array_keys($lookup_array);
708: $firstRow = array_pop($f);
709: if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) {
710: return PHPExcel_Calculation_Functions::REF();
711: } else {
712: $columnKeys = array_keys($lookup_array[$firstRow]);
713: $returnColumn = $columnKeys[--$index_number];
714: $firstColumn = array_shift($columnKeys);
715: }
716: }
717:
718: if (!$not_exact_match) {
719: uasort($lookup_array,array('self','_vlookupSort'));
720: }
721:
722: $rowNumber = $rowValue = False;
723: foreach($lookup_array as $rowKey => $rowData) {
724: if ((is_numeric($lookup_value) && is_numeric($rowData[$firstColumn]) && ($rowData[$firstColumn] > $lookup_value)) ||
725: (!is_numeric($lookup_value) && !is_numeric($rowData[$firstColumn]) && (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)))) {
726: break;
727: }
728: $rowNumber = $rowKey;
729: $rowValue = $rowData[$firstColumn];
730: }
731:
732: if ($rowNumber !== false) {
733: if ((!$not_exact_match) && ($rowValue != $lookup_value)) {
734:
735: return PHPExcel_Calculation_Functions::NA();
736: } else {
737:
738: $result = $lookup_array[$rowNumber][$returnColumn];
739: if ((is_numeric($lookup_value) && is_numeric($result)) ||
740: (!is_numeric($lookup_value) && !is_numeric($result))) {
741: return $result;
742: }
743: }
744: }
745:
746: return PHPExcel_Calculation_Functions::NA();
747: }
748:
749:
750: 751: 752: 753: 754: 755: 756: 757: 758:
759: public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) {
760: $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
761: $index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
762: $not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
763:
764:
765: if ($index_number < 1) {
766: return PHPExcel_Calculation_Functions::VALUE();
767: }
768:
769:
770: if ((!is_array($lookup_array)) || (empty($lookup_array))) {
771: return PHPExcel_Calculation_Functions::REF();
772: } else {
773: $f = array_keys($lookup_array);
774: $firstRow = array_pop($f);
775: if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) {
776: return PHPExcel_Calculation_Functions::REF();
777: } else {
778: $columnKeys = array_keys($lookup_array[$firstRow]);
779: $firstkey = $f[0] - 1;
780: $returnColumn = $firstkey + $index_number;
781: $firstColumn = array_shift($f);
782: }
783: }
784:
785: if (!$not_exact_match) {
786: $firstRowH = asort($lookup_array[$firstColumn]);
787: }
788:
789: $rowNumber = $rowValue = False;
790: foreach($lookup_array[$firstColumn] as $rowKey => $rowData) {
791: if ((is_numeric($lookup_value) && is_numeric($rowData) && ($rowData > $lookup_value)) ||
792: (!is_numeric($lookup_value) && !is_numeric($rowData) && (strtolower($rowData) > strtolower($lookup_value)))) {
793: break;
794: }
795: $rowNumber = $rowKey;
796: $rowValue = $rowData;
797: }
798:
799: if ($rowNumber !== false) {
800: if ((!$not_exact_match) && ($rowValue != $lookup_value)) {
801:
802: return PHPExcel_Calculation_Functions::NA();
803: } else {
804:
805: $result = $lookup_array[$returnColumn][$rowNumber];
806: return $result;
807: }
808: }
809:
810: return PHPExcel_Calculation_Functions::NA();
811: }
812:
813:
814: 815: 816: 817: 818: 819: 820: 821:
822: public static function LOOKUP($lookup_value, $lookup_vector, $result_vector=null) {
823: $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
824:
825: if (!is_array($lookup_vector)) {
826: return PHPExcel_Calculation_Functions::NA();
827: }
828: $lookupRows = count($lookup_vector);
829: $l = array_keys($lookup_vector);
830: $l = array_shift($l);
831: $lookupColumns = count($lookup_vector[$l]);
832: if ((($lookupRows == 1) && ($lookupColumns > 1)) || (($lookupRows == 2) && ($lookupColumns != 2))) {
833: $lookup_vector = self::TRANSPOSE($lookup_vector);
834: $lookupRows = count($lookup_vector);
835: $l = array_keys($lookup_vector);
836: $lookupColumns = count($lookup_vector[array_shift($l)]);
837: }
838:
839: if (is_null($result_vector)) {
840: $result_vector = $lookup_vector;
841: }
842: $resultRows = count($result_vector);
843: $l = array_keys($result_vector);
844: $l = array_shift($l);
845: $resultColumns = count($result_vector[$l]);
846: if ((($resultRows == 1) && ($resultColumns > 1)) || (($resultRows == 2) && ($resultColumns != 2))) {
847: $result_vector = self::TRANSPOSE($result_vector);
848: $resultRows = count($result_vector);
849: $r = array_keys($result_vector);
850: $resultColumns = count($result_vector[array_shift($r)]);
851: }
852:
853: if ($lookupRows == 2) {
854: $result_vector = array_pop($lookup_vector);
855: $lookup_vector = array_shift($lookup_vector);
856: }
857: if ($lookupColumns != 2) {
858: foreach($lookup_vector as &$value) {
859: if (is_array($value)) {
860: $k = array_keys($value);
861: $key1 = $key2 = array_shift($k);
862: $key2++;
863: $dataValue1 = $value[$key1];
864: } else {
865: $key1 = 0;
866: $key2 = 1;
867: $dataValue1 = $value;
868: }
869: $dataValue2 = array_shift($result_vector);
870: if (is_array($dataValue2)) {
871: $dataValue2 = array_shift($dataValue2);
872: }
873: $value = array($key1 => $dataValue1, $key2 => $dataValue2);
874: }
875: unset($value);
876: }
877:
878: return self::VLOOKUP($lookup_value,$lookup_vector,2);
879: }
880:
881: }
882: