You could use a function like this:
<?php
function isNestedArrayEmpty($parentArray, $parentKey, $childKeys)
{
if (empty($parentArray))
return TRUE;
$node = $parentArray[$parentKey];
if (empty($node))
return TRUE;
if (!empty($childKeys))
{
foreach ($childKeys as $key)
{
if (empty($node[$key]))
return TRUE;
$node = $node[$key];
}
}
return false;
}
?>
Then call the function like this:
if (isNestedArrayEmpty($container, 'progress', $arr_1)) { ... }
if (isNestedArrayEmpty($container, 'progress', $arr_2)) { ... }
if (isNestedArrayEmpty($container, 'progress', $arr_3)) { ... }
Here is a complete working example, using the arrays you provided. (Note: I removed the square brackets around the keys in the intializers for $arr_1, $arr_2 and $arr_3, as this seems to be a syntax error).
<html>
<body>
<?php
function isNestedArrayEmpty($parentArray, $parentKey, $childKeys)
{
if (empty($parentArray))
return TRUE;
$node = $parentArray[$parentKey];
if (empty($node))
return TRUE;
if (!empty($childKeys))
{
foreach ($childKeys as $key)
{
if (empty($node[$key]))
return TRUE;
$node = $node[$key];
}
}
return false;
}
$arr_1 = array(0 => 'setup');
$arr_2 = array(0 => 'artwork', 1 => 'path');
$arr_3 = array(0 => 'artwork', 1 => 'color');
$container = array(
'progress' => array(
'setup' => 'complete',
'artwork' => array(
'path' => 'complete',
'color'=> '',
)
)
);
echo '$container[\'progress\'] empty?: ';
if (isNestedArrayEmpty($container, 'progress', NULL)) {
echo 'Yes';
} else {
echo 'No';
}
echo '<br>';
echo '$container[\'progress\'][\'setup\'] empty?: ';
if (isNestedArrayEmpty($container, 'progress', $arr_1)) {
echo 'Yes';
} else {
echo 'No';
}
echo '<br>';
echo '$container[\'progress\'][\'artwork\'][\'path\'] empty?: ';
if (isNestedArrayEmpty($container, 'progress', $arr_2)) {
echo 'Yes';
} else {
echo 'No';
}
echo '<br>';
echo '$container[\'progress\'][\'artwork\'][\'color\'] empty?: ';
if (isNestedArrayEmpty($container, 'progress', $arr_3)) {
echo 'Yes';
} else {
echo 'No';
}
echo '<br>';
?>
</body>
</html>
Output from the above example:
$container['progress'] empty?: No
$container['progress']['setup'] empty?: No
$container['progress']['artwork']['path'] empty?: No
$container['progress']['artwork']['color'] empty?: Yes