Home > Backend Development > PHP Tutorial > How to remove empty elements from an array in PHP

How to remove empty elements from an array in PHP

巴扎黑
Release: 2016-11-23 11:49:28
Original
1296 people have browsed it

The problem is encountered when using the function explode().

There is a string whose format is a set of keywords separated by commas. In PHP, you can use the function

explode() to convert these keywords Extract it into an array and save it. There may be empty elements in the saved array, for example, when the initial string is: ',keyword 1,,keyword 2,'.

How to remove them?

Through Google, I found the following two web articles about using the function array_filter() to solve this problem.

1. PHP removes empty values ​​​​in the array

2. The php function array_filter() filters the php empty array_php removes the empty array_array Key name reset serialization


Of course, for the use of array_filter(), you should read the documentation for more information.

Related labels:
php
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