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

巴扎黑
巴扎黑Original
2016-11-24 09:08:381602browse

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 combine 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.

Statement:
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
Previous article:php—goto statementNext article:php—goto statement