Home >Backend Development >PHP Problem >How to clear empty array in php
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)].
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:
<?php $arr = array( 0=>'cyy', 1=>false, 2=>-1, 3=>null, 4=>'' ); print_r(array_filter($arr));
Output result:
##Related learning recommendations:
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!