想在php中动态显示开放时间

时间:2016-03-28 10:02:00

标签: php arrays database

您好我想显示我正在通过数据库动态获取的营业时间。这是

的数组
  Array
(
    [from] => Array
        (
            [0] => 09:30
            [1] => 09:30
            [2] => 09:30
            [3] => 09:30
            [4] => 09:30
            [5] => 09:30
            [6] => 09:30
        )

    [to] => Array
        (
            [0] => 18:30
            [1] => 18:30
            [2] => 18:30
            [3] => 18:30
            [4] => 18:30
            [5] => 18:30
            [6] => 18:30
        )

)

现在我想要的是,如果时间等于星期五那么它将显示时间Mon-Fri然后Sat Sun closed或者如果时间相同直到星期六那么它将显示星期一至星期六,如果整周时间相同,然后显示Mon-Sun。希望我能告诉你我到底想要什么。这是我的PHP代码

更新了答案

 $result = array_unique($time['from']);
if (count(array_unique($time['from'])) == 3)
 {
    echo '<li><strong>Mon-Fri:</strong><span>' . $time['from'] . ' to ' .  $time['to'] . '</span></li>
        <li>
          <strong>Sat-Sun:</strong>
          <span>'. $time['from'][6] .'</span>
        </li>';
 } else if(count(array_unique($time['from'])) == 2) 
 {
   echo '<li><strong>Mon-sat:</strong><span>' . $time['from'][0] . ' to ' . $time['to'][0] . '</span></li>
    <li>
      <strong>Sun:</strong>
      <span>'. $time['from'][6] .'</span>
    </li>';
 }
else if(count(array_unique($time['from'])) == 1) {
    echo '<li><strong>Mon - Sun:</strong><span>' . $time['from'][0] . ' to ' . $time['to'][0] . '</span></li>';
                        }

0 个答案:

没有答案