This is a fairly quick question.
I'm designing a PHP menu system based on an array of items.
The problem is I want to have submenus and so on.
The way I've decided to do this is in the array...
Code: Select all
<?php
$menu['Home'] = 'cat|';
$menu['News'] = 'item|news.php';
$menu['Archive'] = 'item|archive.php';
$menu['Publications'] = 'cat|';
$menu['AMD'] = 'item|testamd.php';
$menu['Editorial Policy'] = 'sub|test1.php';
$menu['Advertising'] = 'sub|test2.php';
$menu['Schedule'] = 'sub|test3.php';The first value before the | character is what type of menu item this is.
It can either be cat, item or sub. Cat is a category heading, item is a normal menu item, sub is a submenu item. And they'll work in that heirarchical order.
The next value after the | pipe character is the URL.
Now I may end up with 70 or so items in this array.
Obviously only a selection of those will be visible as items marked 'sub' will only be visible if the parent page is being displayed.
I have that sorted though I think.
The next section of my code is to go through each item in the array, do explode() on each array value to parse each item before and after the | delimeter into a sort of sub-array (I know that's not a very technical term but it kindof explains what I'm driving at I think).
Then if the current page equals the URL after one of the | it will show the submenus, if not then it won't.
My question is this...
$menu might end up with 70-100 items in this array.
Will there be a massive processing overhead in parsing each array value into a sub-array based on the | separator I've chosen?
Don't forget the values of each one of these $menu items will have to be split into two other values either side of the | delimeter.
Is this a feasible way to approach this or is there an easier way?
I don't want to add massive processing time to my page.
I thought that setting up the menu in this way is one of the easiest ways for me to update but if anyone has any other suggestions then please let me know.
I don't want to go down the line of a database driven menu structure as I don't think the site will become large enough.
Is there a faster way to do this than looping and parsing each array value into another sub-array?
I'm worried that for 70-100 array items there could be noticeable slowdown.
Any suggestions?
Thanks
Ben