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

How to clear empty array in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-05 13:19:164162browse

php method to clear empty arrays: use the [array_filter()] function in the php code to remove the empty array, the syntax is [array_filter($array,$callback,$flag)].

How to clear empty array in php

php method to clear empty arrays:

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

Sample code:

'cyy',
    1=>false,
    2=>-1,
    3=>null,
    4=>''
);
print_r(array_filter($arr));

Output result:

How to clear empty array in php

##Related learning recommendations:

php graphic tutorial

The above is the detailed content of How to clear 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