Skip to content

Instantly share code, notes, and snippets.

@giovanniramos
Last active September 29, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovanniramos/1542593 to your computer and use it in GitHub Desktop.
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
<?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