array_filter
array_filter — Filters elements of an array using a callback function.Description
array_filter( array $array, ?callable $callback = null, int $mode = 0 ): arrayIterates over each value in the array passing them to the callback function. If the callback function returns true, the current value from array is returned into the result array. Array keys are preserved, and may result in gaps if the array was indexed. The result array can be reindexed using the array_values() function.
Parameters
array
The array to iterate over
callback
The callback function to use
If no callback is supplied, all empty entries of array will be removed. See empty() for how PHP defines empty in this case.
mode
Flag determining what arguments are sent to callback:
ARRAY_FILTER_USE_KEY - pass key as the only argument to callback instead of the value
ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to callback instead of the value
Default is 0 which will pass value as the only argument to callback instead.
Return Values
Returns the filtered array.More information about array_filter on official PHP documentation site
array_filter - Popular snippets
- PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
last run:
2024-11-28 10:37:58
25
- PHP 8.0 / MySQL 5.7 array_count_values print_r array_filter
last run:
2023-09-12 07:03:45
25
- PHP 8.0 / MySQL 5.7 implode array_filter preg_match array_map strlen range
last run:
2021-05-02 20:42:52
16
- PHP 8.1 / MySQL 5.7 preg_match array_filter var_dump
last run:
2024-11-05 10:05:49
15
- PHP 7.4 / MySQL 5.7 array_count_values print_r array_filter
last run:
2022-12-27 17:59:29
10
- PHP 7.4 / MySQL 5.7 array_count_values array_keys array_filter print_r
last run:
2023-03-17 08:49:11
9
- PHP 8.1 / MySQL 5.7 print_r array_filter array_count_values
last run:
2022-08-11 02:17:19
9
- PHP 8.0 / MySQL 5.7 array_filter var_export
last run:
2021-09-09 04:28:57
9
- PHP 8.1 / MySQL 5.7 json_decode preg_match array_filter var_dump str_replace
last run:
2023-08-30 06:27:32
8
- PHP 8.0 / MySQL 5.7 array_filter array_keys is_numeric print_r
last run:
2022-02-21 10:31:17
8
array_filter - New snippets
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-29 10:08:25
3
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-29 10:08:20
1
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-29 10:08:08
3
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-29 10:07:32
2
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-29 10:07:27
2
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-28 10:41:37
4
-
PHP 8.1 / MySQL 5.7 array_filter array_map array_values print_r
added at:
2024-11-28 10:41:09
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower print_r
added at:
2024-11-26 15:23:09
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-11-26 15:22:31
1
-
PHP 8.1 / MySQL 5.7 array_keys implode array_map array_filter print_r
added at:
2024-11-12 03:42:21
1