doukun1450 2019-05-13 09:24
浏览 57
已采纳

检查两次之间的时间(用户输入)(来自foreach)

I want to check if a user entered a time (start, end) which already exist or have a conflict with the times out of the foreach.

I tried to put the existing times in an array to check the new user data with the data from the array but it didnt worked :I

if(isset($_POST['submit'])){
    $mitarbeitername = $_POST['mitarbeiter'];
    //echo "Organisator: " .$mitarbeitername;

    $reservierungvon = $_POST['zeitstart'];
    //echo "Von: " .$reservierungvon;

    $reservierungbis = $_POST['zeitende'];
    //echo "Bis: " .$reservierungbis;
}

foreach($value as $value) {
    $startarray[] = $start = $value->Start->DateTime;($value);
}

$checkendtime = array();
foreach($value as $value) {
    $endarray[] = $start = $value->End->DateTime;($value);
}

if ($reservierungvon == $startarray || $reservierungbis == $endarray || $reservierungvon < $startarray && $endarray > $reservierungbis) {
    echo "conflict!";
} else {
    echo "no conflict!";
}

This is the foreach where im getting the existing meeting-times:

foreach ($result->value as & $value) {
                $start = $value->Start->DateTime;
                $start = substr($start, 11, -11);
                $ende = $value->End->DateTime;
                $ende = substr($ende, 11, -11);
                $organisierer = $value->Organizer->EmailAddress->Name;
}

And in this form the user can create new meetings if there isnt some conflicts with existings meetings:

<label for="psw"><br><b>Zeit der Reservierung:</b></label><br>
von <input type="time" name="timestart"> Uhr bis <input type="time" name="timeend"> Uhr <br>

It would be great if I can check the times out of the foreach with the new times from the user.

The user will get a message if there is a conflict or not. So he can correct his times.

Thanks for any help! :)

  • 写回答

1条回答 默认 最新

  • dongra1984 2019-05-13 09:41
    关注

    You need to check in the loop or otherwise the following scenarios:

    For each existing interval (B):

    1. The entered interval starts within B
    2. The entered interval ends within B
    3. The entered interval starts before B and ends after B

    if any of these are TRUE you have a conflict, otherwise not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度