Last active
September 29, 2015 03:48
-
-
Save giovanniramos/1542593 to your computer and use it in GitHub Desktop.
Checks through recursion, a list of keys that have a value EMPTY or NULL
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
<?php | |
/** | |
* Checks through recursion, a list of keys that have a value EMPTY or NULL | |
* | |
* @param array $haystack A simple/multi-dimensional array | |
* @param string $mandatory List with the names of keys that will be checked, separated by commas | |
* @return boolean | |
* | |
* */ | |
function is_arrayEmpty($haystack, $mandatory = null) | |
{ | |
foreach ($haystack as $k => $v) { | |
if (is_array($v)) { | |
is_arrayEmpty($v, $mandatory); | |
} else { | |
if (in_array($k, preg_split('~[\s,]+~', $mandatory)) && $v == '') { | |
return true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment