multidimensional array + nested foreach = a real mess!!
Posted: Thu Mar 10, 2005 4:19 am
Hi
I'm developing a new navigation script on my site and a preview of it can be seen in action here...
http://www.dealer-world.com/test2.php
The navigation is difficult to explain so you'd better take a look around the page to give it a go first.
It all revolves around detecting which page your currently viewing by checking the values of $p and $s from the address bar.
P is a page, and s is like a subsection of that page.
Some of the links have subsections (AMD and Big Book), but most of them don't.
You'll notice the links with subsections (AMD and Big Book) have multidimensional arrays to list the subsections.
The array data is all delimited by three colons ::: as in each array item there are three bits of data stored.
The type of item - is it a header, an item or a sub(item):::The Text That Goes Into The Menu Bar:::and the corresponding value of s or p that we need to compare the address bar to.
Hopefully you'll get a better idea of what I mean if you check out the links to see how it works.
The comments might be pretty useful within the PHP code.
The script is a real mess.
I've been trying to work this out since before christmas and eventually I've got the behaviour I want from the script but it really is all over the place.
The PHP code itself is at
http://www.dealer-world.com/test2.html
As you can see it's horrific to read through.
I'd appreciate it if someone could read through it to spot any ways it can be shortened/improved.
Maybe there's already PHP functions to do most of what I've had to do manually, but I just don't know enough about PHP to shorten this script.
Any ideas on how this can be improved?
Thanks
Batfastad
I'm developing a new navigation script on my site and a preview of it can be seen in action here...
http://www.dealer-world.com/test2.php
The navigation is difficult to explain so you'd better take a look around the page to give it a go first.
It all revolves around detecting which page your currently viewing by checking the values of $p and $s from the address bar.
P is a page, and s is like a subsection of that page.
Some of the links have subsections (AMD and Big Book), but most of them don't.
You'll notice the links with subsections (AMD and Big Book) have multidimensional arrays to list the subsections.
The array data is all delimited by three colons ::: as in each array item there are three bits of data stored.
The type of item - is it a header, an item or a sub(item):::The Text That Goes Into The Menu Bar:::and the corresponding value of s or p that we need to compare the address bar to.
Hopefully you'll get a better idea of what I mean if you check out the links to see how it works.
The comments might be pretty useful within the PHP code.
The script is a real mess.
I've been trying to work this out since before christmas and eventually I've got the behaviour I want from the script but it really is all over the place.
The PHP code itself is at
http://www.dealer-world.com/test2.html
As you can see it's horrific to read through.
I'd appreciate it if someone could read through it to spot any ways it can be shortened/improved.
Maybe there's already PHP functions to do most of what I've had to do manually, but I just don't know enough about PHP to shorten this script.
Any ideas on how this can be improved?
Thanks
Batfastad