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

How to remove null values ​​from array in PHP?

Guanhui
GuanhuiOriginal
2020-06-06 17:43:112595browse

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

<?php
    $array = array(&#39;a&#39; => "abc", &#39;b&#39; => "bcd",&#39;c&#39; =>"cde",&#39;d&#39; =>"def",&#39;e&#39;=>"");
    $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