Home>Article>Backend Development> How to remove null values from array in PHP?
#How to remove null values from an array in PHP?
In PHP, you can use the "array_filter()" function to remove empty values from the array. This function uses a callback function to filter the elements in the array. Its syntax is "array_filter(array)", and its parameters Array represents the array to be filtered. When using it, just pass the array into array.
Example code
"abc", 'b' => "bcd",'c' =>"cde",'d' =>"def",'e'=>""); $b= array_filter($array); print_r($b); ?>
Result:
Array ( [a] => abc [b] => bcd [c] => cde [d] => def )
Recommended tutorial: "PHP"
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!