NYCPHP Meetup

NYPHP.org

[nycphp-talk] store's opening hours

Stephen Musgrave stephen at musgrave.org
Thu Oct 2 17:16:31 EDT 2003



That's a nice piece of work.  Thank you so much... Something certainly to
learn from!



On 10/2/03 3:42 PM, "David Sklar" <sklar at sklar.com> wrote:

> $open_close = array('Mon' => array('10:00','4:00'),
>                   'Tue' => array('10:00','4:00'),
>                   'Wed' => array('10:00','3:30'),
>                   'Thu' => array('10:00','4:00'),
>                   'Fri' => array('10:00','4:00'),
>                   'Sat' => array('9:00','5:00'),
>                   'Sun' => array('9:00','5:00'));
> 
> $days = array_keys($open_close);
> // The first line of hours starts with the first day
> $first_day = $days[0];
> for ($i = 0, $j = count($open_close); $i < $j; $i++) {
>   // What's the name of the current day?
>   $today = $days[$i];
>   if (($i == ($j - 1)) || // Is this the last day?
>       (($tomorrow = $days[$i+1]) &&  // What's the name of tomorrow?
>        // Does tomorrow open at a different time than today?
>        (($open_close[$today][0] != $open_close[$tomorrow][0]) ||
>         // Does tomorrow close at a different time than today?
>         ($open_close[$today][1] != $open_close[$tomorrow][1])))) {
> 
>       // If it's the last day, or tomorrow's times are different
>       // than today's times, then report the times for
>       // $first_day to $today
>       printf("%s%s %4s to %4s\n",
>              // Don't print "Mon-Mon", just print "Mon";
>              ($first_day == $today) ? '    ' : $first_day.'-',
>              $today,
>              $open_close[$today][0],
>              $open_close[$today][1]);
>       // The next line of output starts with tomorrow
>       $first_day = $tomorrow;
>   }
> }




More information about the talk mailing list