drxnfdx798517235 2011-01-31 01:11
浏览 25

需要帮助排序多个数组

I see a lot of examples here, but it's not working for me.

I have a list of sorted events retrieved from my DB:

16.08.2010 12:00:00 - 21.08.2010 20:00:00
16.08.2010 20:00:00 - 21.08.2010 23:00:00
18.08.2010 17:00:00 - 18.08.2010 19:00:00

As you can see, the first event is from 16.08 to 21.08.
I need to "chop this up" so that I get one entry foreach day.

This is my function:

  function fullList( $data ) {
    $ev = $data['events']; 
    $events = array();

    // Loop through each event. If event spans over several days, add each day in to new event list  
    foreach($ev as $e) :
      $endDate = strtotime(date('Y-m-d 23:59:59', strtotime($e->endTime)));
      $current = strtotime($e->startTime);

      // Copy event so data is not overwritten
      $newEv = $e;

      while ($current <= $endDate) {

          //Set start date of event to new date
          $newEv->startTime = date('d.m.Y H:i:s', $current);

          // Add events to new event list
          array_push($events,$newEv);

          //Go to next date
          $current = strtotime('+1 day', $current);
      }      
    endforeach;
    // Need to sort $events here
  }

Now $events contains all events, but it's not sorted by date. I've tried uasort, but I can't use uasort($array, 'cmp');.

How can I go about sorting this array by date?

  • 写回答

2条回答 默认 最新

  • duancong2160 2011-01-31 01:20
    关注

    Have you tried natural sorting algorithm?

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大