Created
December 28, 2014 05:20
-
-
Save iforwms/0add569ae88d57f15b6d to your computer and use it in GitHub Desktop.
PHP: Remove Empty Values From Array
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
//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