Forum Moderators: coopster

Message Too Old, No Replies

manipulating multiple arrays

complex array problem

         

iluvthsgam

2:16 am on Nov 20, 2008 (gmt 0)

10+ Year Member



Here is the setup. This is for a practice/game schedule function. I have 7 different arrays (one for each team). Each array contains anywhere from 3 or 4 to 14 or 15 entries. Each entry has information like start-timestamp, end-timestamp, location, description, etc.

I need to output all the information from all the arrays at once.

For example,

Monday
11under 5-7pm High School
12under 7-9pm High School

Tuesday
12under 3-5pm Middle School
11under 5-7pm Middle School

Can anybody point me in a theoretical right step? I'm sitting here trying to figure out how I am going to approach this and can't come up with any good ideas.

The problem I run into is that EACH day's practices must be sorted in time-order. The 5pm practice should be listed before the 7pm practice (regardless of which team is practicing).

Pico_Train

5:02 am on Nov 20, 2008 (gmt 0)

10+ Year Member



check out the ksort and key functions on php.net. My first thought is to put all the teams schedules by day so that the days of the week are the keys of the arrays. Then merge arrays where the key is the same. Then sort somehow to order by time.

cameraman

5:03 am on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sort each of the 7 arrays by start-timestamp, then go through the time period you're looking at (the week, for example) and determine the start & end time stamps for each of the days. Then for each day, look at the seven arrays for which elements apply to that day.

iluvthsgam

7:12 am on Nov 20, 2008 (gmt 0)

10+ Year Member



@cameraman - say for example I am looking at Monday. I look at each Array to see if there is a date in Monday. What if 2 arrays both have events on a Monday. How can I then figure out which one occurs first before printing them out to the screen?

iluvthsgam

7:58 am on Nov 20, 2008 (gmt 0)

10+ Year Member



Okay I think I have it where I need it - I just need some last minute help.

I have an array for each day of the week (a monday array, a tuesday array, etc.).

Each array is an array of array's. So Monday[0] will contain an array that is filled with event info as described above. Monday[1] will have another array that is filled with event info as described above.

How can I then sort the MONDAY array so that each item (which is an array) is sorted numerically by starttime (which is one of fields in each array), so that I can just then print out the monday array in order - which would be in time order once sorted.

Couldn't figure this one out! Thanks!

iluvthsgam

8:27 am on Nov 20, 2008 (gmt 0)

10+ Year Member



actually with more research I figured it out. I needed to write a little compare function, and then use usort. Got it working perfectly!

cameraman

2:53 pm on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good job, congratulations!