Beispiel #1
0
 protected function array_depth(array $array)
 {
     if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
         return (int) self::parameters(['array' => DT::TYPE_ARRAY])->call(__FUNCTION__)->with($array)->returning(DT::UINT8);
     } else {
         return (int) array_depth($array);
     }
 }
Beispiel #2
0
 function array_depth($array)
 {
     $max_depth = 1;
     foreach ($array as $value) {
         if (is_array($value)) {
             $max_depth = array_depth($value) + 1;
         }
     }
     return $max_depth;
 }
 /**
  * Test the depth of an array
  */
 public function testArrayDepth()
 {
     $array1 = ['fii' => 3, 'faa' => 2, 'foo' => 1];
     $array2 = [];
     $array3 = ['fee' => false, 'foo' => ['faa' => ['fii' => 0]], 'fuu' => 0];
     $array4 = ['foo' => ['faa' => ['fii' => ['fuu' => 0]]]];
     $this->assertEquals(array_depth($array1), 0);
     $this->assertEquals(array_depth($array2), 0);
     $this->assertEquals(array_depth($array3), 2);
     $this->assertEquals(array_depth($array4), 3);
 }
Beispiel #4
0
function array_depth(array $array)
{
    $max_depth = 1;
    $array['$__compute_array_depth_flag'] = 1;
    foreach ($array as $value) {
        if (is_array($value) && !isset($value['$__compute_array_depth_flag'])) {
            $depth = array_depth($value) + 1;
            if ($depth > $max_depth) {
                $max_depth = $depth;
            }
        }
    }
    unset($array['$__compute_array_depth_flag']);
    return $max_depth;
}
Beispiel #5
0
/**
 * ARRAY DEPTH
 * How deep is the array
 *
 * @param array $array the chosen array
 * @return int the number of depth
 */
function array_depth(array $array)
{
    $max_depth = 1;
    foreach ($array as $value) {
        if (is_array($value)) {
            $depth = array_depth($value) + 1;
            if ($depth > $max_depth) {
                $max_depth = $depth;
            }
            echo '<pre>';
            var_export($value);
            echo '</pre>';
        }
    }
    return $max_depth;
}
Beispiel #6
0
function array_depth($array, $depth_count = -1, $depth_array = array())
{
    $depth_count++;
    if (is_array($array)) {
        foreach ($array as $key => $value) {
            $depth_array[] = array_depth($value, $depth_count);
        }
    } else {
        return $depth_count;
    }
    foreach ($depth_array as $value) {
        $depth_count = $value > $depth_count ? $value : $depth_count;
    }
    return $depth_count;
}
Beispiel #7
0
 private static function simple_line($output, &$params)
 {
     $data = $output['data'];
     if (array_depth($data) == 1) {
         $min = min(array_merge(array(0), $data));
         $max = max($data);
     } else {
         $min = min(array_merge(array(0), reset($data)));
         $max = count(reset($data)) ? max(reset($data)) : 0;
     }
     $params['cht'] = 'lc';
     if (array_depth($data) == 1) {
         $params['chd'] = 't:' . implode(',', $data);
     } else {
         $value = array();
         foreach ($data as $one_data) {
             $value[] = implode(',', $one_data);
         }
         $params['chd'] = 't:' . implode('|', $value);
     }
     $params['chds'] = $min . ',' . $max;
     $params['chxr'] = '1,' . $min . ',' . $max;
     $params['chxt'] = 'x,y';
     $params['chs'] = array_key_exists('size', $output) ? $output['size'] : '400x250';
     if (array_key_exists('legend', $output)) {
         $legend = $output['legend'];
         if (is_array($legend)) {
             $legend = '0:|' . implode('|', $legend);
         }
     } else {
         if (array_depth($data) == 1) {
             //use this instead of array_keys to keep the order
             $values = array();
             foreach ($data as $key => $value) {
                 $values[] = $key;
             }
             $legend = '0:|' . implode('|', $values);
         } else {
             //use this instead of array_keys to keep the order
             $values = array();
             foreach (reset($data) as $key => $value) {
                 $values[] = $key;
             }
             $legend = '0:|' . implode('|', $values);
         }
     }
     if ($legend) {
         $params['chxl'] = $legend;
     }
     if (array_depth($data) > 1) {
         if (array_key_exists('colors', $output)) {
             $params['chco'] = implode(',', $output['colors']);
         } else {
             $params['chco'] = implode(',', self::$colors);
         }
         if (array_key_exists('series', $output)) {
             $params['chdl'] = implode('|', $output['series']);
         }
     }
     return self::$url . '?' . http_build_query($params);
 }
 /**
  * Calculate the depth index of an array
  *
  * @param $array
  *
  * @return int;
  */
 function array_depth(array $array)
 {
     $max_depth = 0;
     foreach ($array as $value) {
         if (is_array($value)) {
             $depth = array_depth($value) + 1;
             if ($depth > $max_depth) {
                 $max_depth = $depth;
             }
         }
     }
     return $max_depth;
 }
Beispiel #9
0
function array_depth($array)
{
    $ini_depth = 0;
    foreach ($array as $arr) {
        if (is_array($arr)) {
            $depth = array_depth($arr) + 1;
            if ($depth > $ini_depth) {
                $ini_depth = $depth;
            }
        }
    }
    return $ini_depth;
}