Remove empty values from array in PHP without looping

PHP provides an in-built function “array_filter” that removes all the key value pairs from the array that contain blank or null value.

Syntax:
array array_filter($arrayName)

Example:

$arr1 = array(0 => "text", 1 => false, 2 => null, 3 => -1, 4 => '');
print_r(array_filter($arr1));

The above code will print:

Array(
[0] => text
[3] => -1
)

  1. A person necessarily assist to make critically posts I would state. That is the very first time I frequented your web page and so far? I surprised with the analysis you made to create this actual put up amazing. Fantastic job!

  2. whoah this blog is fantastic i like reading your articles. Stay up the great work! You realize, many individuals are looking around for this information, you can help them greatly.

  3. An intriguing discussion is worth comment. I believe that you simply should certainly write alot more on this topic, it could not be a taboo subject but usually consumers are not sufficient to speak on such topics. To the next. Cheers

  4. Hello! I just would like to give an enormous thumbs up for the wonderful information you’ve got here on this post. I will likely be coming back to your weblog for more soon.

  5. This honestly answered my dilemma, thank you!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>