Home>Article>Backend Development> How to remove null values from array in PHP?

How to remove null values from array in PHP?

Guanhui
Guanhui Original
2020-06-06 17:43:11 2561browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to convert HTML to PHP? Next article:How to convert HTML to PHP?