Function name: Array_filter ()
Call mode: Array_filter ($array)
Parameter description: $array is the object of operation, we will delete the empty element
Instance:
| The code is as follows |
Copy Code |
|
<?php
$array = (' A ' => ' abc ', ' B ' => ' BCD ', ' C ' => ' CDE ', ' d ' => ' def ', ' e ' => ');
Array_filter ($array);
echo "<pre>";
Print_r ($array);
?>
Results:
Array (
[A] => ABC
[b] => BCD
[C] => CDE
[d] => def
) |
foreach or while, using these two syntactic constructs to delete the empty elements in the array, the simple code is as follows:
| The code is as follows |
Copy Code |
|
<?php
foreach ($arr as $k => $v) {
if (! $v)
Unset ($arr [$k]);
}
> |
And I feel very good, but this is not high efficiency has been tried, first $arr into objects, and then take advantage of the characteristics of the object to delete, because: foreach is the current operation of the array into
Line copy, each operation of foreach, is a copy of a variable, the page if there are too many foreach, will be a very large consumption.