Home >Backend Development >PHP Problem >How to remove emptiness from php array but not zero

How to remove emptiness from php array but not zero

藏色散人
藏色散人Original
2021-09-02 09:05:341480browse

The way to remove empties without removing zeros from a PHP array is to use strlen as the callback function, and the code statement for its implementation is such as "array_filter($array, 'strlen');".

How to remove emptiness from php array but not zero

The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

php How to empty an array Not going to zero?

Specific problem description:

I want to remove NULL, FALSE and '' values. I've used array_filter but that also removes the 0's.

Is there any way?

array(NULL,FALSE,'',0,1) -> array(0,1)

Solution:

From http://php.net/manual/en/function.array-filter.php#111091:

If you want to delete NULL, FALSE and empty strings, but keep the value 0, you can use strlen as the callback function:

array_filter($array, 'strlen');

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove emptiness from php array but not zero. For more information, please follow other related articles on the PHP Chinese website!

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