PHP-Code in navigation/01_step/../Navi-Projekt/class/NavigationStep1_1.class.php

<?php
class NavigationStep1_1 {

	public function writeNav($navArr) {
		$code = "";
		$code .= "<nav>\n";
		// Home Link
		$code .= "<div>\n";
		$code .= "<a href=\"index.php\">Home</a>";
		$code .= "</div>\n";
		// Main part of navigation: 
		$code .= "<ul>\n";
		// The 1st Level of the navigation
		foreach ($navArr as $key => $out1) {
			$code .= "<li>\n";
			// Is it a menu item with a dropdown or just one single link?
			if (count($out1) == 1) {
				$path = $key."/".$out1[0]['fileName'];
				$code .= "<a href=\"".$path."\">".$key."</a>\n";
			}
			// It's menu item with a dropdown
			else {
				$code .= "<a href=\"#\">";
				$code .= $key;
				$code .= " ▾</a>\n";
				// The 2nd Level of the navigation
				$code .= "<ul>\n";
				foreach ($out1 as $out2) {
					$code .= "<li>\n";
					$path = $key."/".$out2['fileName'];
					$code .= "<a href=\"".$path."\">".$out2['linkText']."</a>";
					$code .= "</li>\n";
				}
				$code .= "</ul>\n";
			}
			$code .= "</li>\n";
		}
		$code .= "</ul>\n";
		// Hamburger
		$code .= "<div>\n";
		$code .= "<button type=\"button\">☰</button>\n";
		$code .= "</div>\n";
		$code .= "</nav>\n";
		return $code;
	}
}
?>