Home >Backend Development >PHP Tutorial >Use of php array_filter function (detailed explanation)
php array_filter function usage (detailed explanation)
1, array_filter
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
array_filter — Use the callback function to filter the cells in the array
2. Description
array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
Pass each value in the array array to the callback function in turn. If the callback function returns true, the current value of the array array will be included in the returned result array. The key names of the array remain unchanged.
3. Parameters
array: the array to be looped
callback: the callback function used
(If no callback function is provided, all entries in the array with a value equal to FALSE will be deleted. See Converting to Boolean values for more information.)
flag: Determines the ## the callback receives. #Parameter form, as follows:
① ARRAY_FILTER_USE_KEY - callback accepts the key name as the only parameter
② ARRAY_FILTER_USE_BOTH - callback accepts both key name and key value
4, return value
returns the filtered array. array_filter is actually a very easy-to-use function. Commonly used scenarios include multi-condition filtering on forms. You can directly use this function to filter out filter items without values.array_filter will filter out any value equal to FALSE, that is to say, 0 value, empty string, null, will be filtered
PHP Tutorial"
The above is the detailed content of Use of php array_filter function (detailed explanation). For more information, please follow other related articles on the PHP Chinese website!