SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: availability chart array
-
May 23, 2003, 13:41 #1
- Join Date
- Sep 2000
- Location
- Ontario, Canada
- Posts
- 320
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
availability chart array
I need to create a daily availability chart and currently am using multidimensional arrays to assign which day/timeslot is chosen. My problem is that in doing so, I have to create 7 "foreach" statements to go through each of the days to pick out the timeslot values.
ie.
avail[mon][1] (morning)
avail[tues][2] (afternoon)
avail[wed][4] (evening)
avail[thurs][8] (night)
etc.
I need to loop through these values in order to use bitwise calculation. The user can have multiple choices in the same day so the obtained bit values would have to be added accordingly.
Is there any way to get around using 7 loops to create the bit value?
Any suggestions are greatly appreciated
-
May 23, 2003, 13:45 #2
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The data in the arrays - where is it from I ask ? ie is it from a database....
If so, maybe there is a more direct way to use this data....
I'm starting to think Objects here. First though you'd need to break down the amount of permutations that could take place I think so we can have a more general idea of what possibilities there could be with this data....
Or is it just me thinking aloud
-
May 23, 2003, 13:52 #3
- Join Date
- Sep 2000
- Location
- Ontario, Canada
- Posts
- 320
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for your response...
This part of the data is taken directly from a user input chart. The bit value created by the array calculations will then be inserted into the database.
The user will be able to choose one or all of morning, afternoon, evening and night from each of the 7 days.
-
May 29, 2003, 13:51 #4
- Join Date
- Sep 2000
- Location
- Ontario, Canada
- Posts
- 320
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just to recap, I have altered my code to use day numbers instead of day names. Then I used a loop to go through the day numbers.
PHP Code:for($day=0; $day<7; $day++) {
// $day[0] is mon; $day[1] is tues; ...
}
If $avail[1][]=2 and $avail[1]=4, how do I add those 2+4 in the loop shown above?
I tried array_sum() but that sums the entire array, not array values associated with the same key.
-
May 29, 2003, 14:02 #5
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If $avail[1][]=2 and $avail[1]=4, how do I add those 2+4 in the loop shown above?
PHP Code:$avail[1][0]=2
$avail[1][1]=4, etc ?
-
May 29, 2003, 14:12 #6
- Join Date
- Sep 2000
- Location
- Ontario, Canada
- Posts
- 320
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oops, it is a typo, sorry! The chart will create output like:
PHP Code:$avail[1][]=1
$avail[1][]=4
$avail[2][]=2
$avail[2][]=8 etc.
Bookmarks