Skip to content

Instantly share code, notes, and snippets.

@iforwms
Created December 28, 2014 05:20
Show Gist options
  • Save iforwms/0add569ae88d57f15b6d to your computer and use it in GitHub Desktop.
Save iforwms/0add569ae88d57f15b6d to your computer and use it in GitHub Desktop.
PHP: Remove Empty Values From Array
//RMEOVE ALL EMPTY VALUES FROM ARRAY
function arrayNonEmptyItems($input)
{
// If it is an element, then just return it
if (!is_array($input)) {
return $input;
}
$non_empty_items = array();
foreach ($input as $key => $value) {
// Ignore empty cells
if ($value) {
// Use recursion to evaluate cells
$non_empty_items[$key] = array_non_empty_items($value);
}
}
// Finally return the array without empty items
return $non_empty_items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment