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-12-13 14:17:06
27
- 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 preg_match_all array_filter in_array strtolower print_r
added at:
2024-12-17 07:48:07
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower print_r
added at:
2024-12-17 07:47:25
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower print_r
added at:
2024-12-17 07:46:48
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower print_r
added at:
2024-12-17 07:45:40
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:45:30
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:45:20
2
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:45:05
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:44:39
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:44:33
1
-
PHP 8.1 / MySQL 5.7 preg_match_all array_filter in_array strtolower
added at:
2024-12-17 07:44:23
1