Php array filter by value
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8) Show array_filter — Filters elements of an array using a callback function Descriptionarray_filter(array Array keys are preserved, and may result in gaps if the Parametersarray The array to iterate over callback The callback function to use If no mode Flag determining what arguments are sent to
0
which will pass value as the only argument to callback instead. Return ValuesReturns the filtered array. Changelog
ExamplesExample #1 array_filter() example
even($var) The above example will output: Odd : Array ( [a] => 1 [c] => 3 [e] => 5 ) Even: Array ( [0] => 6 [2] => 8 [4] => 10 [6] => 12 ) Example #2 array_filter() without
= [ The above example will output: Array ( [0] => foo [2] => -1 ) Example #3 array_filter() with
= ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];var_dump(array_filter($arr, function($k) { The above example will output: array(1) { ["b"]=> int(2) } array(2) { ["b"]=> int(2) ["d"]=> int(4) } NotesCaution If the array is changed from the callback function (e.g. element added, deleted or unset) the behavior of this function is undefined. See Also
Anonymous ¶ 9 years ago
nicolaj dot knudsen at gmail dot com ¶ 5 years ago
ASchmidt at Anamera dot net ¶ 1 year ago
TechNyquist ¶ 4 months ago
marc dot vanwoerkom at fernuni-hagen dot de ¶ 18 years ago
marc dot gray at gmail dot com ¶ 8 years ago
Niko E ¶ 12 days ago
justinphiggs at gmail dot com ¶ 2 months ago
$array_count === $filtered_count ) ? true : false; How do you filter a two dimensional array by value?PHP array_filter() function filters elements of an array by a callback function and it can be used for many purposes. The array_filter() function provides a short and simple way to filter multidimensional array by key and value.
Is value in array PHP?The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.
What are PHP filters?PHP filters are used to validate and sanitize external input. The PHP filter extension has many of the functions needed for checking user input, and is designed to make data validation easier and quicker.
|