0

我正在尝试输出一个包含事件的数组,准确地说是 ical 文件输出。数组本身如下所示:

  Array (
    [0] => Array (
        [UID] => 4C2DDB6E-5B5B-4B97-BEBE-FF424BB154F8
        [DTEND] => 20131116 [SUMMARY] => test1_ONS
        [LAST-MODIFIED] => 20131111T210530Z
        [DTSTAMP] => 20131111T213437Z
        [DTSTART] => 20131112
        [LOCATION] => City
        [SEQUENCE] => 1
        [DESCRIPTION] => description here_http://www.test.com/test1
        [SUMMARY] => some text here
) )

我可以使用以下 foreach 循环遍历其记录并输出所有事件:

    foreach ($events_sorted as $event) {
$client = current(explode("_", $event['SUMMARY']));
} and so on...

棘手的部分是我的事件表布局基于月份,如下所示:

             CLIENT   EXHIBITION   CITY
_________________________________________
OCT 2013     client   exhibition   city
             client   exhibition   city
             client   exhibition   city
________________________________________
NOV 2013     client   exhibition   city
             client   exhibition   city
________________________________________
DEC 2013     client   exhibition   city

我无法做的是循环遍历所有事件,根据布局输出一次相应的月份名称,输出相应事件的数据并继续下个月。

然而,我的表格布局是按照其第一行包含月份名称数据的方式构建的,并且必须以某种方式与包含事件的所有其他行区分开来:

<table id="table_events">
                <tbody><tr id="header_row">
                <th id="date_header"></th>
                <th></th>
                <th></th>
                <th></th>
                </tr>

                <tr class="month_start">
                <td>
                <div class="month_rect">
                    <div class="month_rect_text month_long">SEPT</div>
                    <div class="month_rect_year">2013</div>
                </div>
                </td>
                <td>eee</td>
                <td>eee</td>
                <td>Oslo</td>
                </tr>

                <tr>
                <td>
                    </td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>

                <tr>
                    <td></td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>
                <tr id="oct" class="month_start">
                <td>
                <div class="month_rect">
                    <div class="month_rect_text month_short">OCT</div>
                    <div class="month_rect_year">2013</div>
                </div>
                </td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>
                <tr>
                <td>
                    </td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>
                <tr class="month_start">
                <td>
                <div class="month_rect">
                    <div class="month_rect_text month_short">NOV</div>
                    <div class="month_rect_year">2013</div>
                </div>
                </td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>

                <tr>
                <td>
                    </td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                </tr>

                </tbody></table>

到目前为止,我还尝试根据月份创建新数组,但也没有运气:

 foreach($events_sorted as $test) {
$month_number = gmdate("m", $ical->iCalDateToUnixTimestamp($test['DTSTART']));

$r = array("month" => $month_number);

}

我的最后一个想法是打印出所有事件并通过重置数组检查是否存在月份名称,如果存在则不要再次输出它并使用不同的表格行布局,但我不确定如何实现这个解决方案。我希望有更简单的方法来实现描述的效果

4

1 回答 1

1
<table>
    <tr>
      <td width="20%"></td>
      <td>CLIENT</td>
      <td>EXHIBITION</td>
      <td>CITY</td>
    </tr>
    <?php $last_event = NULL; ?>
    <?php foreach($events as $event) : ?>
    <tr>
      <td><?php if($last_event != NULL) : if($last_event['DATE'] != $event['DATE']) : echo $event['DATE']; endif; else : echo $event['DATE']; endif; ?></td>
      <td><?php echo $event['CLIENT']; ?></td>
      <td><?php echo $event['EXHIBITION']; ?></td>
      <td><?php echo $event['CITY']; ?></td>
    </tr>
    <?php $last_event = $event; ?>
    <?php endforeach; ?>
  </table>

有一个$last_event变量将保存已通过的每个事件foreach。循环中有一条if语句确定 是否与$last_event行中的当前事件具有相同的日期。如果是,那么它将通过而不打印日期,如果不是,那么它将打印它。在循环结束之前,有一个分配为$last_event下一次确定分配当前通过的事件。这是我能解释的最简单的形式。

现在,如果您不想仅仅通过打印它们来猜测相似的日期,那是另一种情况。

于 2013-11-13T22:40:09.873 回答