Remove null values from an Array in PHP
Today we will see how we can easily remove any null value from an Array in PHP. For this we will use array_filter() function. And the important thing is we don’t need any loop to complete the task. So lets see the example.
Example
$data = array("Mehadi Hasan", "Hello User", null, 11, "",null, 77,"Here is the data");
$output = array_filter($data, function($value) {
return !is_null($value);
});
print_r($output);
Output
Array
(
[0] => Mehadi Hasan
[1] => Hello User
[3] => 11
[4] =>
[6] => 77
[7] => Here is the data
)