How to Remove empty elements from an array in PHP

Source: Internet
Author: User
The problem occurs when the function explode () is used. there is a string in the format of a set of keywords separated by commas. in PHP, you can use the function explode () to extract these keywords into an array and save them. an empty element may exist in the saved array. for example, when the initial string is:, Keyword 1, keyword 2 ,. how to remove them? Use Google to find the following two web pages to address... the problem is encountered when the function explode () is used.

There is a string in the format of a comma-separated keyword. in PHP, you can use the function

Explode (), extract these keywords into an array to save. the saved array may contain empty elements. for example, when

The initial string is ', Keyword 1, keyword 2 ,'.

How to remove them?

Google finds the following two web pages and describes how to use the array_filter () function to solve this problem.

1. PHP removes null values from the array

2. php function array_filter () filter php empty array _ php remove empty array _ array key name reset serialization


Of course, for the use of array_filter (), please refer to the document for more information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.