3v4l.org

run code in 300+ PHP versions simultaneously
<?php <?php $paths = array( 'about/contact/' => 'Contact Us', 'about/contact/form/' => 'Contact Form', 'about/history/' => 'Our History', 'about/staff/' => 'Our Staff', 'about/staff/bobjones/' => 'Bob', 'about/staff/sallymae/' => 'Sally', 'products/' => 'All Products', 'products/gifts/' => 'Gift Ideas!', 'products/widgets/' => 'Widgets' ); function build_tree($path_list) { $path_tree = array(); foreach ($path_list as $path => $title) { $list = explode('/', trim($path, '/')); $last_dir = &$path_tree; foreach ($list as $dir) { $last_dir =& $last_dir[$dir]; } $last_dir['__title'] = $title; } return $path_tree; } function build_list($tree, $prefix = '') { $ul = ''; foreach ($tree as $key => $value) { $li = ''; if (is_array($value)) { if (array_key_exists('__title', $value)) { $li .= "$prefix$key/ <a href=\"/$prefix$key/\">${value['__title']}</a>"; } else { $li .= "$prefix$key/"; } $li .= build_list($value, "$prefix$key/"); $ul .= strlen($li) ? "<li>$li</li>" : ''; } } return strlen($ul) ? "<ul>$ul</ul>" : ''; } $tree = build_tree($paths); $list = build_list($tree); echo $list; ?>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.6
Parse error: syntax error, unexpected '<', expecting end of file in /in/7kJUK on line 3
Process exited with code 255.

preferences:
172.9 ms | 1395 KiB | 35 Q