Fix maxDimensions() for empty/1 dimensional arrays.

maxDimensions() should not emit warnings or mis-calculate an array's
dimensions.

Fixes #6224
This commit is contained in:
mark_story 2015-03-31 22:21:15 -04:00
parent 758820d7cc
commit 69971505a2
2 changed files with 14 additions and 2 deletions

View file

@ -763,10 +763,14 @@ class Hash {
$depth = array();
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
$depth[] = self::dimensions((array)$value) + 1;
if (is_array($value)) {
$depth[] = self::dimensions($value) + 1;
} else {
$depth[] = 1;
}
}
}
return max($depth);
return empty($depth) ? 0 : max($depth);
}
/**