Created
February 25, 2014 13:40
-
-
Save joseporiol/9208891 to your computer and use it in GitHub Desktop.
Removes empty entries from a array recursivly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_remove_empty($arr){ | |
$narr = array(); | |
while(list($key, $val) = each($arr)){ | |
if (is_array($val)){ | |
$val = array_remove_empty($val); | |
// does the result array contain anything? | |
if (count($val)!=0){ | |
// yes :-) | |
$narr[$key] = $val; | |
} | |
} | |
else { | |
if (trim($val) != ""){ | |
$narr[$key] = $val; | |
} | |
} | |
} | |
unset($arr); | |
return $narr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment