1. ## 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

2. 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

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.

4. 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; ... }  ```
This solves part of the problem however I realized that I now have another problem.

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.

5. If \$avail[1][]=2 and \$avail[1]=4, how do I add those 2+4 in the loop shown above?
Don't you mean the following ? Or is the above \$avail structure correct ? ...

PHP Code:
``` \$avail[1][0]=2\$avail[1][1]=4, etc ?  ```
A typo or am I reading it wrong ?

6. 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.  ```
Currently, as the loop goes through, I can get the values but I need to add the values if the keys are the same.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•