need vector-like functionality
Posted: Thu Nov 16, 2006 4:12 pm
feyd | Please use
i hope the helps clarify things.
thanks
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi all
i need to generate a 3-tier menu system dynamically and thus want something like a 3d vector. but i cannot find any vector functions in php, only arrays.
but from what i understand about theory of programming, 3d arrays cannot be dynamic. well... i bet they can but i need something simple like myVector.pushBack(item) or even myVector.pushBack(anotherVector) etc.
i am pulling a list of items from a database. each item has a name, a category, a sub-category, and a type.
in order to generate the 3 tier menu i need to be able to dynamically alter the 3d vector as i iterate through each item. know what i mean?
how do i implement 3d vectors in php? or more simply, how do i implement a vector that can be dynamically altered?
i have code to do exactly what i want in python. now i am trying to do the same in php.
the python code:
[syntax="python"]
base = {}
for item in items:
if not base.has_key(item.category):
base[item.category] = {}
if not base[item.category].has_key(item.type)
base[item.category][item.type] = {}
if not base[item.category][item.type].has_key(item.brand)
base[item.category][item.type][item.brand] = []
base[item.category][item.type][item.brand].append(item.name)
for cat in base.keys():
print cat
for typ in base[cat].keys():
print typ
for brand in base[cat][typ].keys():
print brand
for item in base[cat][typ][brand]:
print item
thanks
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]