Skip to content

Instantly share code, notes, and snippets.

@joseporiol
Created February 25, 2014 13:40
Show Gist options
  • Save joseporiol/9208891 to your computer and use it in GitHub Desktop.
Save joseporiol/9208891 to your computer and use it in GitHub Desktop.
Removes empty entries from a array recursivly
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