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.

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

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题