Home > Article > Backend Development > How to remove emptiness from php array but not zero
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');".
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!