Generating Deep Arrays: Shallow to Deep, Deep to Shallow or Bad idea?
Posted
by
MobyD
on Programmers
See other posts from Programmers
or by MobyD
Published on 2012-11-21T21:18:45Z
Indexed on
2012/11/21
23:11 UTC
Read the original article
Hit count: 338
data-structures
|array
I'm working on an array structure that will be used as the data source for a report template in a web app.
The data comes from relatively complex SQL queries that return one or many rows as one dimensional associative arrays. In the case of many, they are turned into two dimensional indexed array.
The data is complex and in some cases there is a lot of it. To save trips to the database (which are extremely expensive in this scenario) I'm attempting to get all of the basic arrays (1 and 2 dimension raw database data) and put them, conditionally, into a single, five level deep array. Organizing the data in PHP seems like a better idea than by using where statements in the SQL.
Array Structure
Array of years(
year => array of types(
types => array of information(
total => value,
table => array of data(
index => db array
)
)
)
)
My first question is, is this a bad idea. Are arrays like this appropriate for this situation?
If this would work, how should I go about populating it? My initial thought was shallow to deep, but the more I work on this, the more I realize that it'd be very difficult to abstract out the conditionals that determine where each item goes in the array. So it seems that starting from the most deeply nested data may be the approach I should take.
If this is array abuse, what alternatives exist?
© Programmers or respective owner