Home >Backend Development >PHP Tutorial >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!