Home > Article > Backend Development > How to remove null values from array in php
We can use the array_filter() function to achieve this.
Function introduction:
array_filter() function uses a callback function to filter elements in the array.
This function will pass each key value in the input array to the callback function. If the callback function returns true, the current key value in the input array is returned to the result array. Array key names remain unchanged.
Code example:
<?php $array = array('a' => "abc", 'b' => "bcd",'c' =>"cde",'d' =>"def",'e'=>""); $b= array_filter($array); print_r($b); ?>
The results are as follows:
Array ( [a] => abc [b] => bcd [c] => cde [d] => def )
For more related tutorials, please visit php Chinese website.
The above is the detailed content of How to remove null values from array in php. For more information, please follow other related articles on the PHP Chinese website!