PHP implements the method to remove an empty array or a value element.

Source: Internet
Author: User
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!

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.