# filter()

{% code title="Example.php" %}

```php
<?php use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from(range(1, 10));

//Filtering values ​​between 3 and 6
$arrayUtils->filter(function($num){ return $num < 3 || $num > 6; });
// expected output: [1, 2, 7, 8, 9, 10]
```

{% endcode %}

## Syntax

```php
$arrayUtils->filter(callable $callback) : ArrayUtils;
```

### Parameter

* `$callback`

  > A function to test each element of the array.\
  > Return a value that coerces to `TRUE` to keep the element, or to `FALSE` otherwise.\
  > Function taking three arguments:
  >
  > * `$value` The current element being processed in the array.
  > * `$key` The index of the current element being processed in the array.
  > * `$array`  The array `every` was called upon.

### Return value

* A filtered array.

## Prefixing

```php
$arrayUtils->filterAs(callable $callback) : array;
```

```php
ArrayUtils::filterFrom(iterable $from, callable $callback) : ArrayUtils;
```

```php
ArrayUtils::filterFromAs(iterable $from, callable $callback) : array;
```

## References

{% embed url="<https://www.php.net/manual/en/function.array-filter.php>" %}

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arrayutils.docs.present.kim/methods/c/filter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
