views:

32

answers:

1

I'm currently having difficulty finding a way of making my loops work.

I have a table of data with 15 minute values. I need the data to pull up in a few different increments

$filters=Array('Yrs','Qtr','Day','60','30','15');

I think I have a way of finding out what I need to be able to drill down to but the issue I'm having is after the first loop to cycle through all the Outter most values (ex: the user says they want to display by Hours, each hour should be able to have a "+" that will then add a new div to display the half hour data, then each half hour data have a "+" to display the 15 minute data upon request.

Now I can just program the number of outputs for each value (6 different outputs) just in-case... but isn't there a way I can make it do the drill down for each one in a loop? so I only have to code one output once and have it just check if there are any more intervals after it and check for those? I'm sure I'm just overlooking some very simple way of doing this but my brain isn't being clever today. Sorry in advance if this is a simple solution.

I guess the best way I could think of it as a reply on a form. How you would check to see if it's a reply of a reply, and then if that reply has any replys...etc for output.

Can anyone help or at least point me in the right direction? Or am I stuck coding each possible check?

Thanks in advance!

+1  A: 

It's called "recursive" programming. Find a common theme in your values and look into writing a function that can call itself.

Check out this tutorial: http://www.programminginterview.com/content/recursion

It basically involves taking a value, checking it conditionally, and then calling back on the function to do so again (or, in some cases, do something else with the value). It's a great way to drill down through multidimensional arrays that don't have any sort of fixed depth.

dclowd9901
Thanks much I actually did this, I just didn't think to put it in a function! I seem to be on the right track now thanks for your assistance!
stogdilla
I hear ya. I really only recently finally "got" recursion. It was like a light switch. If this works out for you, don't hesitate to vote up/select for answer ;)
dclowd9901
you got it, thanks much! I do get it. How genius, a function that calls itself. The sad part is I've done this before just never knew it had a name. No matter how great you think you are, there's always more! Thanks again.
stogdilla
So, I guess, in a way, if you think about it, you invented recursion :)
dclowd9901
probably true, are there any royalties for this?
stogdilla