How to remove empty values from array in PHP?

By Hardik Savani | February 28, 2016 | | 37623 Viewer | Category : PHP


you have array with empty value and you want to remove all empty value from that array without loop. you can remove your all empty value from array without loop. PHP array_filter function through you can remove all empty value, you can do both way try and see following example how to do this :

Example:

$example = array(100, "hari", "","hey", "", 77, "hello");

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

return !empty($value);

});

print_r($result);


$resultDirect = array_filter($example);

print_r($resultDirect);

Output:

Array

(

[0] => 100

[1] => hari

[3] => hey

[5] => 77

[6] => hello

)




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.