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

Guanhui
Release: 2023-03-01 13:00:02
Original
2591 people have browsed it

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);
?>
Copy after login

Result:

Array (
[a] => abc
[b] => bcd
[c] => cde
[d] => def
)
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!