SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    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
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    Non-Member
    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

  3. #3
    SitePoint Addict
    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.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  4. #4
    SitePoint Addict
    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; ...

    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.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  5. #5
    Non-Member
    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?
    Don't you mean the following ? Or is the above $avail structure correct ? ...

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

  6. #6
    SitePoint Addict
    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
    Currently, as the loop goes through, I can get the values but I need to add the values if the keys are the same.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net


Bookmarks

Posting Permissions

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