I'm trying to create a data structure consisting of nested associative arrays.
It is created by:
Taking an array from a query result using mysql_fetch_array($result, MYSQL_ASSOC).
Then iterate through this array. Each attribute name in this array is compared to a lookup table which will determine whether the attribute value references another table, i.e. the value is a code that is the primary key of another table.
For every attribute value that is a code that has a table to reference, fetch the data and replace the original string value (in the first array) with this new array.
And so on.
There could be anything from 0 to 5 levels to fetch referenced tuple data for, so I've been trying to come up with a recursive function to do this, but have failed so far.
Does anybody have any tips for iterating through such a simple structure, and applying a function to each member like the above; or maybe a link to an article that has a strategy?
I am of course not looking for code from you, I'm probably just missing some convenient PHP construct for doing this.
but I can't see how I could use this, as although it would be great to get the information out, am I wrong in thinking it's not so great for the creation of the above data structure?
Any thoughts on this would be greatly appreciated.
Seems you have a kind of tree-like structure. There are better methods to handle it than recursive queries. Find a site point article about this (keyword: nested sets).
Bookmarks