Categorized | News

Filtering Out Blanks from an Array

Posted on 29 January 2003 by Demian Turner

Amazing the little tricks you can pick up from combing the PHP manual, especially in the comments.

I particularly like this one-liner, which allows you to filter out blanks or empty elements from an array.

Bookmark and Share

1 Comments For This Post

  1. Anonymous Says:

    This also works.

    $array_with_empty = array(\"one\",\"\",\"three\",\"\",\"five\");

    $cleaned_array = array_diff( $array_with_empty , array(NULL) );

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook