<?php
$items = [
(object)['level' => '1', 'title' => 'Home'],
(object)['level' => '1', 'title' => 'DIFC'],
(object)['level' => '1', 'title' => 'ADGM'],
(object)['level' => '1', 'title' => 'About'],
(object)['level' => '1', 'title' => 'Publications'],
(object)['level' => '2', 'title' => 'FinTech: Now Everybody Wants A Slice of the Pie'],
(object)['level' => '2', 'title' => 'The Role of Financial Centres in Emerging Economies'],
(object)['level' => '2', 'title' => 'Bitcoin versus Ethereum '],
(object)['level' => '1', 'title' => 'ADGM'],
(object)['level' => '1', 'title' => 'DIFC'],
(object)['level' => '1', 'title' => 'Finance'],
(object)['level' => '1', 'title' => 'Contact']
];
echo '<ul itemscope itemtype="http://www.schema.org/SiteNavigationElement">' . "\n";
foreach ($items as $i => $menu_item) {
if($menu_item->level == '1') {
if ($i) { // so long as not the first row of results
if ($sub_menu) { // only display a batch of submenus if batch is not empty
echo "\n\t\t<ul>\n\t\t\t<li>" . implode("</li>\n\t\t\t<li>", $sub_menu) . "</li>\n\t\t</ul>";
}
echo "\n\t" . '</li>' . "\n";
}
$sub_menu = array(); // start over with a new batch
echo "\t" . '<li itemprop="name">' . "\n";
echo "\t\t" . '<a itemprop="url" href="http://www.10leaves.ae/">' . $menu_item->title . '</a>';
} elseif ($menu_item->level == '2') {
$sub_menu[] = $menu_item->title;
}
}
if ($items) {
echo "\n\t</li>";
}
echo "\n</ul>";
preferences:
61.17 ms | 402 KiB | 5 Q