rrylee
10/15/2015 - 4:12 AM

write a tree mock.

write a tree mock.

<?php

function makeTree($arr) {

    $result = '';

    foreach ($arr as $key => $value) {
        $result .= '<li>' . (is_array($value) ? ($key . makeTree($value)) : $value) . '</li>';
    }

    return "<ul>$result</ul>";
}

$tree = [
    'core' => [
        'app.php',
        'bootstrap.php',
        'autoload.php',
    ],
    'functions' => [
        'config.php',
        'mailer.php',
        'logger.php',
        'includes' => [
            'other.php',
        ],
    ],
    'class' => [
        'PDO.php',
        'Fun.php'
    ],
    'index.php',
    'init.php',
];

echo makeTree($tree);