How to remove null values from array in PHP?

Now in this blog i will show you how to remove null values from an array by using php. When we have an array with null value and we want to remove the all null value from that array also without any loop. Then we can remove our all null value from array without using any loop. We know in PHP array_filter function through we can remove our all null value, we see following the example how to remove null value :


$example = array(100, "srs", null, "hey", NULL, "", 77);
$result = array_filter($example, function($value) {
			  return !is_null($value);



    [0] => 100
    [1] => srs
    [3] => hey
    [5] => 
    [6] => 77


Read Also : How to count number of files in folder and remove all files in folder in laravel example?

Thanks for read this, I hope it will you. You can also follow us on Facebook.

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.