Home  >  Article  >  Backend Development  >  How to remove empty array in php

How to remove empty array in php

Guanhui
GuanhuiOriginal
2020-05-11 14:47:453932browse

How to remove empty array in php

How to remove empty arrays in php

In php, you can remove empty arrays by using "array_filter()". The function of this function is Use the callback function to filter the units in the array. The function syntax is "array_filter($array,$callback,$flag)". When using it, you only need to pass the array into the first parameter.

Sample code:

$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => ''
          );

print_r(array_filter($entry));

Output result:

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

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to remove empty array in php. 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