## How to take the average of several sets of numbers (assigning variable names?)

I'm still fairly new at PHP, and am trying to put together a program for use by myself and a small number of other people. A very simple program already exists and works. I'd like to add some ways that people can retrieve their own data so that they can analyze it and learn from it.

People basically just enter a numerical rating at different times of the day. It could be, for example, the outdoor temperature at any given hours. (It isn't, but that is probably the best example.)

I'd like for people to be able to ascertain their average temperature rating for, say, mornings during the first two weeks of April, 2013. I pretty much understand how to restrict the query to (a) hours between, say, 6 a.m. and noon; and (b) days between April 1 and April 14, 2013.

A twist arises because some days will have more than one morning rating, e.g., temp is 50 at 6:00 a.m.; 60 at 10:00 a.m.; and 65 at 11:45 a.m. So I need to average those temps and then have just one figure for that date.

Bear in mind, please, that I'm still very much a beginner and therefore tend to think in quite simplistic ways! This is basically only my second project and I'm content to proceed in very elementary ways, even if they are not the most efficient. (for now, anyway)

So - I'm imagining a conditional that will say something like: if there is more than one entry for these hours on any given day, then add those entries and average them, and assign the result to variable \$morning_temp; else (if there is only one entry for these hours), then assign that entry to variable \$morning_temp. Then I would want to add them and take their average.

I've boxed myself in, however -- I'm assigning all the temps to the same variable name!

Can anyone tell me please how to get myself out of this corner?

For the moment, at least, I'd like to stay fairly close to this paradigm, as it's one that I understand and could, with some effort, probably implement. There are probably ways that would be much spiffier and more elegant, but there is a significant risk that I would not, at present, understand them.

I'm hoping that someone can nudge me in the right direction.

Thank you!