This article describes how to remove an empty array or a element with a certain value in PHP, and describes how to use array_filter to filter arrays in php, for more information about how to remove null or a value element from an array in PHP, this article describes how to use php to filter arrays using array_filter, for more information, see
This example describes how to remove an empty array or a value element in PHP. We will share this with you for your reference. The details are as follows:
Two functions array_filter and create_function are used to remove an element with an empty project or an element with a certain value in the array.
First look at an instance:
$ 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 );
Returned results:
Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4)
Function introduction: array_filter
The array_filter () function uses the callback function to filter elements in the array. if the custom filter function returns true, the current value of the operated array is included in the returned result array, and form a new array of results. If the original array is an associated array, the key name remains unchanged.
For more articles about how to remove null elements in an array or a value element in PHP, refer to PHP!