Home > Backend Development > PHP Tutorial > PHP filters empty values ​​​​such as 0, null, false and '' in the array

PHP filters empty values ​​​​such as 0, null, false and '' in the array

angryTom
Release: 2023-04-07 16:54:01
forward
3088 people have browsed it

PHP filters empty values ​​​​such as 0, null, false and '' in the array

#PHP has a very complete set of functions for array operations, including filtering null values.

To filter all elements with empty values ​​in the array, you can directly use the array_filter() function. For example:

$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => '',
             5 => 0
          );
print_r(array_filter($entry));
Copy after login

The above code will output:

Array
(
    [0] => foo
    [2] => -1
)
Copy after login

As you can see, the array_filter() function filters all elements whose value is false.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of PHP filters empty values ​​​​such as 0, null, false and '' in the array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:www.awaimai.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template