public static function searchFields($array, $values, $opts = array())
    {
        if (!\is_array($array)) {
            $array = array($array);
        }
        if (!\is_array($opts)) {
            if (\is_bool($opts)) {
                $opts = array(
                    'whole' => $opts,
                    'case'  => $opts,
                );
            } else {
                $opts = array();
            }
        }
        $opts = \array_merge(array(
            'whole' => false,
            'case' => false,
            'first' => false,
        ), $opts);
        /*
            clean up search values
        */
        foreach ($values as $colname => $searchValue) {
            if ($searchValue === null || $searchValue === '') {
                unset($values[$colname]);
                continue;
            }
            if (\is_array($searchValue)) {
                $searchValue = \array_shift($searchValue);
                $values[$colname] = $searchValue;
            }
            if (\is_string($searchValue)) {
                if (!$opts['case']) {
                    $searchValue = \strtolower($searchValue);
                }
                $values[$colname] = \trim($searchValue);
            }
        }
        foreach ($array as $key => $row) {
            $match = true;
            foreach ($values as $colname => $searchValue) {
                $colValue = isset($row[$colname])
                    ? $row[$colname]
                    : null;
                if (\is_string($colValue)) {
                    if (!$opts['case']) {
                        $colValue = \strtolower($colValue);
                    }
                    $colValue = \trim($colValue);
                }
                if (\is_bool($searchValue)) {
                    $found = $colValue == $searchValue;
                } elseif ($opts['whole']) {
                    $found = $colValue == $searchValue;
                } else {
                    $found = \strpos($colValue, (string) $searchValue) !== false;
                }
                if (!$found) {
                    $match = false;
                    unset($array[$key]);
                    continue;
                }
            }
            if ($match && $opts['first']) {
                return $row;
            }
        }
        if ($opts['first']) {
            return false;
        }
        return $array;
    }