31 public static function MATCH($lookupValue, $lookupArray, $matchType = self::MATCHTYPE_LARGEST_VALUE)
35 $matchType = ($matchType === null)
36 ? self::MATCHTYPE_LARGEST_VALUE
41 self::validateLookupValue($lookupValue);
42 self::validateMatchType($matchType);
43 self::validateLookupArray($lookupArray);
45 $keySet = array_keys($lookupArray);
46 if ($matchType == self::MATCHTYPE_LARGEST_VALUE) {
48 $lookupArray = array_reverse($lookupArray);
49 $keySet = array_reverse($keySet);
52 $lookupArray = self::prepareLookupArray($lookupArray, $matchType);
54 return $e->getMessage();
58 if (is_string($lookupValue)) {
64 case self::MATCHTYPE_LARGEST_VALUE:
65 $valueKey = self::matchLargestValue($lookupArray, $lookupValue, $keySet);
68 case self::MATCHTYPE_FIRST_VALUE:
69 $valueKey = self::matchFirstValue($lookupArray, $lookupValue);
72 case self::MATCHTYPE_SMALLEST_VALUE:
74 $valueKey = self::matchSmallestValue($lookupArray, $lookupValue);
77 if ($valueKey !== null) {
87 $wildcardLookup = ((bool) preg_match(
'/([\?\*])/', $lookupValue));
88 $wildcard = WildcardMatch::wildcard($lookupValue);
90 foreach ($lookupArray as
$i => $lookupArrayValue) {
91 $typeMatch = ((gettype($lookupValue) === gettype($lookupArrayValue)) ||
92 (is_numeric($lookupValue) && is_numeric($lookupArrayValue)));
95 $typeMatch && is_string($lookupValue) &&
96 $wildcardLookup && WildcardMatch::compare($lookupArrayValue, $wildcard)
100 } elseif ($lookupArrayValue === $lookupValue) {
111 foreach ($lookupArray as
$i => $lookupArrayValue) {
112 $typeMatch = ((gettype($lookupValue) === gettype($lookupArrayValue)) ||
113 (is_numeric($lookupValue) && is_numeric($lookupArrayValue)));
115 if ($typeMatch && ($lookupArrayValue <= $lookupValue)) {
116 return array_search(
$i, $keySet);
130 foreach ($lookupArray as
$i => $lookupArrayValue) {
131 $typeMatch = gettype($lookupValue) === gettype($lookupArrayValue);
133 if ($lookupArrayValue === $lookupValue) {
137 } elseif ($typeMatch && $lookupArrayValue >= $lookupValue) {
139 } elseif ($typeMatch && $lookupArrayValue < $lookupValue) {
151 if ((!is_numeric($lookupValue)) && (!is_string($lookupValue)) && (!is_bool($lookupValue))) {
160 ($matchType !== self::MATCHTYPE_FIRST_VALUE) &&
161 ($matchType !== self::MATCHTYPE_LARGEST_VALUE) && ($matchType !== self::MATCHTYPE_SMALLEST_VALUE)
170 $lookupArraySize = count($lookupArray);
171 if ($lookupArraySize <= 0) {
179 foreach ($lookupArray as
$i => $value) {
181 if ((!is_numeric($value)) && (!is_string($value)) && (!is_bool($value)) && ($value !== null)) {
185 if (is_string($value)) {
190 (($matchType == self::MATCHTYPE_LARGEST_VALUE) || ($matchType == self::MATCHTYPE_SMALLEST_VALUE))
192 unset($lookupArray[
$i]);
static validateLookupArray($lookupArray)
const MATCHTYPE_SMALLEST_VALUE
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static matchFirstValue($lookupArray, $lookupValue)
const MATCHTYPE_FIRST_VALUE
static MATCH($lookupValue, $lookupArray, $matchType=self::MATCHTYPE_LARGEST_VALUE)
MATCH.
const MATCHTYPE_LARGEST_VALUE
static matchSmallestValue($lookupArray, $lookupValue)
static prepareLookupArray($lookupArray, $matchType)
static matchLargestValue($lookupArray, $lookupValue, $keySet)
static validateLookupValue($lookupValue)
static strToLower($pValue)
Convert a UTF-8 encoded string to lower case.
static validateMatchType($matchType)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.