Skip to content

Instantly share code, notes, and snippets.

@sweikenb
Created February 6, 2019 11:28
Show Gist options
  • Save sweikenb/80ec5b38a7ceef49ad18c5c48c654402 to your computer and use it in GitHub Desktop.
Save sweikenb/80ec5b38a7ceef49ad18c5c48c654402 to your computer and use it in GitHub Desktop.
PHP array practice
<?php
/*
* Conditions:
***********************************************************************************************************************
*
* Do not modify or edit this file/array -> include it into your working file and use the $navigation array as it is.
*
*
* Tasks:
***********************************************************************************************************************
*
* 1. Render an HTML navigation using <ul> and <li> tags
* 2. Highlight the clicked menu item using <strong> tag, if no page is selected highlight the startpage
* 3. Also mark all parents of the selected menu item (see example)
*
*
* Example for taks 3
***********************************************************************************************************************
*
* In case you clicked "Project B" the following elements should be highlighted:
*
* "About Us" + "Portfolio" + "Project B"
*
*/
$navigation = [
[
'id' => 'startpage',
'label' => 'Startpage',
'childs' => [
[
'id' => 'offers',
'label' => 'Offers',
'childs' => [],
],
[
'id' => '',
'label' => 'Downloads',
'childs' => [],
],
[
'id' => 'blog',
'label' => 'Blog',
'childs' => [
[
'id' => 'latest',
'label' => 'Latest',
'childs' => [],
],
[
'id' => 'most_comments',
'label' => 'Most Comments',
'childs' => [],
],
],
],
[
'id' => 'publications',
'label' => 'Publications',
'childs' => [],
],
],
],
[
'id' => 'about_us',
'label' => 'About Us',
'childs' => [
[
'id' => 'the_team',
'label' => 'The Team',
'childs' => [],
],
[
'id' => 'portfolio',
'label' => 'Portfolio',
'childs' => [
[
'id' => 'project_a',
'label' => 'Project A',
'childs' => [],
],
[
'id' => 'project_b',
'label' => 'Project B',
'childs' => [],
],
[
'id' => 'project_c',
'label' => 'Project C',
'childs' => [],
],
],
],
],
],
[
'id' => 'products',
'label' => 'Products',
'childs' => [
[
'id' => 'sale',
'label' => 'Sale',
'childs' => [
[
'id' => 'home_decorations',
'label' => 'Home & Decorations',
'childs' => [],
],
[
'id' => 'kitchen',
'label' => 'Kitchen',
'childs' => [
[
'id' => 'sinks',
'label' => 'Sinks',
'childs' => [],
],
[
'id' => 'countertops',
'label' => 'Countertops',
'childs' => [],
],
],
],
],
],
[
'id' => 'crafting_materials',
'label' => 'Crafting Materials',
'childs' => [
[
'id' => 'wood',
'label' => 'Wood',
'childs' => [],
],
[
'id' => 'glass',
'label' => 'Glass',
'childs' => [],
],
[
'id' => 'cloth',
'label' => 'Cloth',
'childs' => [],
],
],
],
],
],
[
'id' => 'contact',
'label' => 'Contact',
'childs' => [
[
'id' => 'impress',
'label' => 'Impress',
'childs' => [],
],
[
'id' => 'legal_notes',
'label' => 'Legal Notes',
'childs' => [],
],
],
],
[
'id' => 'content',
'label' => 'Content',
'childs' => [
[
'id' => 'latest_products',
'label' => 'Latest Products',
'childs' => [],
],
[
'id' => 'catalogs',
'label' => 'Catalogs',
'childs' => [
[
'id' => 'summer_2018',
'label' => 'Summer 2018',
'childs' => [],
],
[
'id' => 'winter_2018',
'label' => 'Winter 2018',
'childs' => [],
],
[
'id' => 'spring_2019',
'label' => 'Spring 2019',
'childs' => [],
],
],
],
],
],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment