This article mainly introduces the method of PHP to remove empty or certain value elements in the array, involving the related operation skills of PHP using array_filter to filter the array. Friends who need it can refer to the example of this article
Describes how PHP implements the method of removing empty or certain value elements from an array. Share it with everyone for your reference, the details are as follows:
Two functions array_filter and create_function are used to remove empty elements or elements with a certain value in the array
Look first An example:
$array = Array ( [0] => 1 ,[1] => 2, [2] => 3, [3] => 4,[4] => '',[5] => '' ); $array = array_filter($array,create_function('$v','return !empty($v);')); print_r($array);
Return result:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
Function introduction: array_filter
array_filter() function uses the callback function to filter the elements in the array. If the custom filter function returns true, the current value of the operated array will be included in the returned result array, and the result will be formed into a new array. If the original array is an associative array, the key names remain unchanged.
For more PHP methods to remove empty or certain value elements from an array, please pay attention to the PHP Chinese website!