Filters a list of objects, based on a set of key => value arguments.

@since 1.5.3
@ticket #1594
@param array        $list to filter.
@param string|array $filter to search for.
@param string       $operator to use (AND, NOT, OR).
@return array
350390
public static function filter_array( $list, $args, $operator = 'AND' ) {
		if ( ! is_array($args) ) {
			$args = array( 'slug' => $args );
		}

		if ( ! is_array( $list ) && ! is_a( $list, 'Traversable' ) ) {
			return array();
		}

		$util = new \WP_List_Util( $list );
		return $util->filter( $args, $operator );
	}
747972
public function removeFilter($field, $operator)
    {
        if (isset($this->filters[$field][$operator])) {
            unset($this->filters[$field][$operator]);
        }

        return $this;
    }
67000
private static function filterInList($operation, &$params)
    {
        $params    = \array_merge($params, \array_values($operation['values']));
        $wildcards = \rtrim(\str_repeat('?,', \count($operation['values'])), ',');

        return \sprintf('(%s IN (%s))', $operation['property'], $wildcards);
    }
136534
private function filterPrefixer(array &$filter)
    {
        foreach ($filter as &$child) {
            if (\array_key_exists('property', $child)
                && (false === \strpos($child['property'], $this->source . '.'))
                && $this->fieldExists($child['property'])
            ) {
                $child['property'] = $this->source . '.' . $child['property'];
            }

            if (\array_key_exists('children', $child)) {
                $this->filterPrefixer($child['children']);
            }
        }
    }
425292
public function filter($filter): ArrayObjectInterface
    {
        return \is_callable($filter, true) ? $this->filterCallback($filter) : $this->filterConditions($filter);
    }
346059
public static function filterByString($filter)
    {
        $operator = Arr::get($filter, 'operator');
        $method = Arr::get($filter, 'method');
        $arguments = Arr::get($filter, 'arguments');
        $value_one = Arr::get($filter, 'value_one');
        $value_two = Arr::get($filter, 'value_two');
        $settings = Arr::get($filter, 'settings');
        $positive = Arr::get($filter, 'positive');

        switch ($operator) {
            case '=':
            case '!=':
                $arguments = [$operator, $value_one];
                break;
            case '*=*':
            case '*!=*':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, '%'.$value_one.'%'];
                break;
            case '*=':
            case '*!=':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, '%'.$value_one];
                break;
            case '=*':
            case '!=*':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, $value_one.'%'];
                break;
            case 'EMPTY':
                $method = 'whereRaw';
                $arguments = "%s = ''";
                break;
            case 'NOT_EMPTY':
                $method = 'whereRaw';
                $arguments = "%s != ''";
                break;
            case 'IN':
                $method = 'whereIn';
                $arguments = [static::getListFromString($value_one)];
                break;
            case 'NOT_IN':
                $method = 'whereNotIn';
                $arguments = [static::getListFromString($value_one)];
                break;
            case 'NULL':
                $method = 'whereNull';
                break;
            case 'NOT_NULL':
                $method = 'whereNotNull';
                break;
        }

        return [
            'operator'  => $operator,
            'method'    => $method,
            'arguments' => $arguments,
            'value_one' => $value_one,
            'value_two' => $value_two,
            'settings'  => $settings,
            'positive'  => $positive,
        ];
    }
852864
protected function convertToArray($data, $filter = 'raw')
    {
        $array = [];

        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $array[$key] = $this->convertToArray($value);
            } else {
                $array[$key] = $this->filter->clean($value, $filter);
            }
        }

        return $array;
    }
162113
protected function operatorForWhere($key, $operator, $value)
    {
        return function ($item) use ($key, $operator, $value) {

            $retrieved = ArrayHelper::dataGet($item, $key);

            switch ($operator) {
                default:
                case '=':
                case '==':
                    return $retrieved == $value;
                case '!=':
                case '<>':
                    return $retrieved != $value;
                case '<':
                    return $retrieved < $value;
                case '>':
                    return $retrieved > $value;
                case '<=':
                    return $retrieved <= $value;
                case '>=':
                    return $retrieved >= $value;
                case '===':
                    return $retrieved === $value;
                case '!==':
                    return $retrieved !== $value;
            }
        };
    }
14398
public function getList($filter = array()) {
        $res = array();
        $dbres = \CAgent::GetList(array("MODULE_ID" => "ASC"), $filter);
        while ($item = $dbres->Fetch()) {
            $res[] = $item;
        }
        return $res;
    }
743849
public function filter($filter = 'image.filters.default')
    {
        $filters = (array) $this->get($filter, []);
        foreach ($filters as $params) {
            $params = (array) $params;
            $method = array_shift($params);
            $this->__call($method, $params);
        }
    }
1160288
public function load($array, $filter=false)
    {
        // apply the optional filter
        if (is_array($filter)) {
            $array = array_intersect_key($array, array_fill_keys($filter, NULL));
        }

        foreach ($array as $key=>$value) {
            if(is_object($value) || is_array($value))
                $this->$key = $value;
            else
                $this->__set($key, $value);
        }

        return $this;
    }
524543
public function where($key, $operator, $value)
    {
        if (string_has($operator, 'IN') || string_has($operator, 'in')) {
            return $this->whereIn($key, $value);
        }

        $this->where[] = 'AND '.$key.' '.$operator.' '.'?';
        $this->bindings[] = $value;

        return $this;
    }
1178801
protected function filter(array $list)
    {
        $tmp = [];
        foreach ($list as $item) {
            if ($item['anime']) {
                $tmp[] = $item;
            }
        }
        return $tmp;
    }
531631
protected function operatorForWhere($key, $operator = null, $value = null)
    {
        if (func_num_args() === 1) {
            $value = true;

            $operator = '=';
        }

        if (func_num_args() === 2) {
            $value = $operator;

            $operator = '=';
        }

        return function ($item) use ($key, $operator, $value) {
            $retrieved = data_get($item, $key);

            $strings = array_filter([$retrieved, $value], function ($value) {
                return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
            });

            if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
                return in_array($operator, ['!=', '<>', '!==']);
            }

            switch ($operator) {
                default:
                case '=':
                case '==':  return $retrieved == $value;
                case '!=':
                case '<>':  return $retrieved != $value;
                case '<':   return $retrieved < $value;
                case '>':   return $retrieved > $value;
                case '<=':  return $retrieved <= $value;
                case '>=':  return $retrieved >= $value;
                case '===': return $retrieved === $value;
                case '!==': return $retrieved !== $value;
            }
        };
    }
1104084
protected function callbackFilterList(array $item, $filter)
    {
        foreach ($filter as $field => $term) {

            if (empty($item[$field])) {
                $item[$field] = '0';
            }

            if (!is_string($item[$field])) {
                $item[$field] = (string) (int) !empty($item[$field]);
            }

            if (stripos($item[$field], $term) === false) {
                return false;
            }
        }

        return true;
    }
691695
protected function supportFilter( array $list = [], bool $enable = true ) {
    foreach( $list as $type ) {
      if( !$enable ) unset( $this->_filter[ $type ] );
      else if( !isset( $this->_filter[ $type ] ) ) $this->_filter[ $type ] = [];
    }

    return $this;
  }
1126196
protected function filterOrCondition(array $data, $operator, $operands)
    {
        $parts = [];
        foreach ($operands as $operand) {
            if (is_array($operand)) {
                $parts[] = $this->filterCondition($data, $operand);
            }
        }

        if (empty($parts)) {
            return $data;
        }

        $data = [];
        foreach ($parts as $part) {
            foreach ($part as $row) {
                $pk = $row[$this->_query->primaryKeyName];
                $data[$pk] = $row;
            }
        }

        return $data;
    }