Home php How to remove empty values from array in PHP?

How to remove empty values from array in PHP?

by Shahriar Sagor

Today now in this blog i will show you how to remove empty values from array in php. When we have an array also with the empty value and we want to remove all empty value from that array also without using any loop. we can remove our all empty value from an array without using loop. For PHP array_filter function through we can remove all empty value, we can also 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
)

Read Also : Laravel and AngularJS CRUD with Search & Pagination Example

Thanks for read. I hope it help you. For more you can follow us on facebook.

close

You may also like