How to remove empty array in php

Guanhui
Release: 2023-04-08 16:32:02
Original
3941 people have browsed it

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));
Copy after login

Output result:

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

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!

Related labels:
source:php.cn
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