31 public static function MATCH($lookupValue, $lookupArray, $matchType = self::MATCHTYPE_LARGEST_VALUE)
35 $matchType = ($matchType ===
null)
36 ? self::MATCHTYPE_LARGEST_VALUE
45 $keySet = array_keys($lookupArray);
46 if ($matchType == self::MATCHTYPE_LARGEST_VALUE) {
48 $lookupArray = array_reverse($lookupArray);
49 $keySet = array_reverse($keySet);
54 return $e->getMessage();
58 if (is_string($lookupValue)) {
77 if ($valueKey !==
null) {
87 $wildcardLookup = ((bool) preg_match(
'/([\?\*])/', $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) &&
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]);
An exception for terminatinating execution or to throw for unit testing.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static wildcard(string $wildcard)
static compare($value, string $wildcard)
static prepareLookupArray($lookupArray, $matchType)
static validateLookupArray($lookupArray)
static matchSmallestValue($lookupArray, $lookupValue)
const MATCHTYPE_LARGEST_VALUE
static MATCH($lookupValue, $lookupArray, $matchType=self::MATCHTYPE_LARGEST_VALUE)
MATCH.
const MATCHTYPE_FIRST_VALUE
static validateLookupValue($lookupValue)
static matchLargestValue($lookupArray, $lookupValue, $keySet)
static validateMatchType($matchType)
static matchFirstValue($lookupArray, $lookupValue)
const MATCHTYPE_SMALLEST_VALUE
static strToLower($pValue)
Convert a UTF-8 encoded string to lower case.