检测数组深度,数据深度,几维数组

/**
 * 检测数据的深度
 * @param $array 要检测的数组
 * @return int   返回深度值
 */
function array_depth($array)
{
    $max_depth = 1;
    foreach ($array as $value) {
        if (is_array($value)) {
            $depth = $this->array_depth($value) + 1;
            if ($depth > $max_depth) {
                $max_depth = $depth;
            }
        }
    }
    return $max_depth;
}

posted on 2023-08-07 19:05  何苦->  阅读(13)  评论(0编辑  收藏  举报

导航