How to remove null values from array in PHP?

By Hardik Savani | January 28, 2016 | Category : PHP

you have array with null value and you want to remove all null value from that array without loop. you can remove your all null value from array without loop. PHP array_filter function through you can remove all null value, you see following example how to remove null value :


$example = array(100, "hardik", null, "hey", NULL, "", 77);

$result = array_filter($example, function($value) {

return !is_null($value);






[0] => 100

[1] => hardik

[3] => hey

[5] =>

[6] => 77


Try this.......

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.