Completed
Push — master ( 7b6a9e...621ea2 )
by Nick
15:23
created

Utility::arrayDepth()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace Acquia\LiftClient\Utility;
4
5
class Utility
6
{
7
    /**
8
   * Define the Depth of an array.
9
   * Proudly found elsewhere.
10
   *
11
   * @see http://stackoverflow.com/a/262944/3664381
12
   *
13
   * @param array $array
14
   *
15
   * @return int
16
   */
17
  public static function arrayDepth(array $array)
18
  {
19
      $max_depth = 1;
20
21
      foreach ($array as $value) {
22
          if (is_array($value)) {
23
              $depth = self::arrayDepth($value) + 1;
24
25
              if ($depth > $max_depth) {
26
                  $max_depth = $depth;
27
              }
28
          }
29
      }
30
31
      return $max_depth;
32
  }
33
}
34