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

How to remove null values ​​from array in php

王林
王林Original
2020-10-29 17:01:284003browse

php method to remove null values ​​​​in an array: You can use the built-in function array_filter() to achieve this, such as [array_filter($array)]. The array_filter() function uses a callback function to filter elements in the array.

How to remove null values ​​from array in php

Function introduction:

array_filter() function uses a callback function to filter elements in the array.

This function passes 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.

(Video tutorial recommendation: php video tutorial)

Grammar format:

array_filter(array)

Parameter description: array is the object of the operation

Example:

 "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
)

Related recommendations:php training

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