PHP method to remove empty or certain value elements from an array

墨辰丷
Release: 2023-03-28 08:58:01
Original
1172 people have browsed it

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 in need can refer to the following

Examples 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);
Copy after login

Return result:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
Copy after login

Function introduction: The array_filter

array_filter() function uses a 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 form the results into a new array. If the original array is an associative array, the key names remain unchanged.

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHP implements the method of outputting the arrangement or combination of multiple elements

php implements the full arrangement of the array, elementsmethods of all combinations

php file_get_contents implements obtaining the array in the file Methods of element

The above is the detailed content of PHP method to remove empty or certain value elements from an array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!