创建和排序数组以按时间排列事件

Create and sort array to arrange events by time

我必须处理的数据如下所示:

<div><strong><?php echo $form_data['field'][86]);?></strong> - Guests find seats</div>
<div><strong><?php echo $form_data['field'][87];?></strong> - Bridal party introductions</div>
<div><strong><?php echo $form_data['field'][88];?></strong> - Dinner is served</div>
<div><strong><?php echo $form_data['field'][92];?></strong> - Cake cutting</div>
<div><strong><?php echo $form_data['field'][96];?></strong> - Speeches</div>
<div><strong><?php echo $form_data['field'][188];?></strong> - Blessing</div>
<div><strong><?php echo $form_data['field'][107];?></strong> - First Dances</div>

但是该示例数据很少是一致的。例如,可能没有切蛋糕,而且显示的顺序不正确。

但是,$form_data 值始终是 24 小时格式(即 14:00、03:30 等)

我希望能够获取所有现有字符串(无论哪个不为空)并创建一个包含时间和事件类型的数组,然后以正确的顺序回显输出。)

因此数组将始终包含这 7 个字符串值,但有时可能只有 5 或 6 个相关。

感谢您提供的任何帮助。

这个想法怎么样。我想我听懂了你的问题,但如果我遗漏了什么,请不要打我。

写一点 PHP 从 $form_data 数组的相关项目中创建一个单独的数组,并将标签添加到该数组,这样你就知道你在页面上放了什么

<?php
    $pickupList = array(86  => 'Guests find seats',
                        87  => 'Bridal party introductions',
                        88  => 'Dinner is served',
                        92  => 'Cake cutting',
                        96  => 'Speeches',
                        188 => 'Blessing',
                        107 => 'First Dances'
                       );

    $event_order = array();

    foreach ( $pickupList as $key=> $label ) {

        if ( $form_data['field'][$key] != '' ) {
            $event_order[$form_data['field'][$key]]  = $label;
        }
    }  

    ksort($event_order);    // sort on key which is a time 12:15

    foreach ( $event_order as $time => $event) {
        echo '<div><strong>';
        echo $time;
        echo '</strong> - ';
        echo $event;
        echo '</div>';
    }