array_filter
Function • Params changed in PHP 8.6
Filters elements of an array using a callback function.
array_filter Function synopsis
array_filter(
array $array,
?callable $callback = null,
int $mode = ARRAY_FILTER_USE_VALUE
): array
Parameters
$array
Typearray
The array to iterate over
$callback
OptionalType?callableDefault valuenull
The callback function to use
$mode
OptionalTypeintDefault valueARRAY_FILTER_USE_VALUE
Flag determining what arguments are sent to $callback:
Default is `0` which will pass value as the only argument
to [`$callback`](#param-callback) instead.
$mode accepts one of the following constant values:
Return value
Typearray
Returns the filtered array.
Changes to the array_filter Function
PHP 8.6
- Parameter default value changed for position #3 (
$mode):0toARRAY_FILTER_USE_VALUE
array_filter(
array $array,
?callable $callback = null,
- int $mode = 0
+ int $mode = ARRAY_FILTER_USE_VALUE
): array PHP 8.0
- Return type added:
array - Parameter name of parameter #1 changed:
$argto$array - Parameter type added for parameter #1 (
$array):array - Parameter type added for parameter #2 (
$callback):?callable - Parameter default value added for position #2 (
$callback):null - Parameter name of parameter #3 changed:
$use_keysto$mode - Parameter type added for parameter #3 (
$mode):int - Parameter default value added for position #3 (
$mode):0
array_filter(
- $arg,
+ array $array,
- $callback,
+ ?callable $callback = null,
- $use_keys
+ int $mode = 0
- )
+ ): array PHP 5.6
- Optional parameter added - #3:
$use_keys
-array_filter($arg, $callback)
+array_filter(
+ $arg,
+ $callback,
+ $use_keys
+ ) array_filter Function Availability
array_filter Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |