深度优先,广度优先,php打印多维数组

把图一的结构转变为图二的结构
 $max_depth) {
                $max_depth = $depth;
            }
        }
    }
    return $max_depth;
}

function array_left($array)
{
    $array_left_count = 0;
    if (is_array($array))
    {
        foreach($array as $key => $value)
        {
            $array_left_count += array_left($value);
        }
        return $array_left_count;
    }
    else
    {
        return 1;
    }
}

function getTableBody($result, $res, $deep, $level)
{
    if(!is_array($result))
    {
        $res .= "" . $result . "";
        for ($i = 0,$crcle = $deep-$level; $i <= $crcle; $i++)
        {
            $res .= "";
        }
        return $res . "";
    }
    else
    {
        foreach($result as $key => $val)
        {
            $count = is_array($val) ? array_left($val) : 1;
            $res .= "{$key}";
            $res .= getTableBody($val, '', $deep,$level+1);
        }
        return $res;
    }
}
$result = array();
$resultHtml = "";
echo getTableBody($all,$resultHtml, array_depth($result), 1) . '
';; exit;


你可能感兴趣的:(php,php,多维数组,表格)