Written by Brian Cray on April 25th, 2009
I had an array with something like the following: Array (  =>  => test  => fun ). But I don't want
, the empty value in the array.
After searching the web for a good solution, I saw that people were using anywhere from 4 to 10+ lines of code to remove null values from arrays. This is obviously overkill so I decided to tackle the problem myself.
Remove NULL values only
$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');
Remove any FALSE values
This includes NULL values, EMPTY arrays, etc. Thanks to Paul Scott for pointing out this method.
$new_array_without_nulls = array_filter($array_with_nulls);