开发者

PHP - Drilling down Data and Looping with Loops

开发者 https://www.devze.com 2022-12-25 03:43 出处:网络
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

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号