我在循环中有时间重叠检查,我还想显示事件 Headers ,结果在另一个数组中 .

没有双foreach循环我可以回显$ event-> title;它会显示所有活动 Headers . 如果我把数组$事件放在$ event-> title中,在foreach中我进行重叠测试它只显示第一个 Headers .

我是PHP的新手,我现在已经用完整的解决方案敲了几天 . 任何帮助都是极好的 :(

while (list(,$event_row) = each($events)) {
  $event->loadEvent($event_row[0]);


  foreach ($events as $thisevent) {
    $event_array = array($event->id,$event->title);
    $conflicts = 0;
    foreach ($events as $thatevent) {
      if ($thisevent[0] === $thatevent[0]) {
        continue;
      }
      $thisevent_from = $thisevent[1];
      $thisevent_ends = $thisevent[2];
      $thatevent_from = $thatevent[1];
      $thatevent_ends = $thatevent[2];
      if ($thatevent_ends > $thisevent_from AND $thisevent_ends > $thatevent_from) {
        echo $event->title;
        $conflicts++;
        echo "Event #" . $thisevent[0] . " overlaps with Event # " . $thatevent[0] . "\n";
      }
    }
    if ($conflicts === 0) {
    echo "Event #" . $thisevent[0] . " is OK\n";
    }
  }
}

如果没有双foreach,var_export($ event)将显示所有事件数组 .

array( 'title' => 'Event 1', 'description' => 'Event description 1', 'contact' => 'event contact 1', 'url' => '', 'link' => '', 'email' => 'event@eventemail.com', 'picture' => '', 'color' => '#009933', 'catName' => 'Events', 'catDesc' => 'General events', 'startDate' => 1432918800, 'endDate' => 1432926000, 'startDay' => 29, 'startMonth' => 5, 'startYear' => 2015, 'endDay' => 29, 'endMonth' => 5, 'endYear' => 2015, 'recurStartDate' => NULL, 'recurEndDate' => NULL, 'id' => '11', 'catId' => 1, 'status' => true, 'recType' => '', 'recInterval' => 0, 'recEndDate' => 1432850400, 'recEndType' => 0, 'recEndCount' => 1, ))

并且var_export($ events)数组显示所有具有id,开始日期和结束日期的数组的三次:

array ( 0 => array ( 0 => '11', 1 => 1432918800, 2 => 1432926000, ), 1 => array ( 0 => '13', 1 => 1432918800, 2 => 1432926000, ), 2 => array ( 0 => '16', 1 => 1432926000, 2 => 1432929600, ), )

感谢您调查并提供任何可能的解决方案提示,想法:)