本文介绍了重新定位基于PHP的一个条件数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有此数组:

$dates[0] = array('start'=>'2010-07-22', 'end'=>'2010-07-23');
$dates[1] = array('start'=>'2010-07-22', 'end'=>'0000-00-00');
$dates[2] = array('start'=>'2010-07-29', 'end'=>'0000-00-00');
$dates[3] = array('start'=>'2010-07-31', 'end'=>'2010-07-31');
$dates[4] = array('start'=>'2010-07-08', 'end'=>'2010-07-31');
$dates[5] = array('start'=>'2010-08-01', 'end'=>'2010-09-30');
$dates[6] = array('start'=>'2010-07-18', 'end'=>'2010-08-15');
$dates[7] = array('start'=>'2010-07-01', 'end'=>'2010-08-31');

和我有以下条件:
如果一个元素'开始'是小于今天,拿着元素的属性'端'和相对于其他要素'开始'

所以,如果一个事件昨天开始明天结束它应该出现的事件后,从今天开始

So if an event started yesterday and ends tomorrow it should appear after the events beginning today

这样的结果数组是这样的:

so the resulting array is something like this:

$dates[3] = array('start'=>'2010-07-22', 'end'=>'2010-07-23');
$dates[4] = array('start'=>'2010-07-22', 'end'=>'0000-00-00');
$dates[5] = array('start'=>'2010-07-29', 'end'=>'0000-00-00');
$dates[6] = array('start'=>'2010-07-31', 'end'=>'2010-07-31');
$dates[1] = array('start'=>'2010-07-08', 'end'=>'2010-07-31');
$dates[7] = array('start'=>'2010-08-01', 'end'=>'2010-09-30');
$dates[2] = array('start'=>'2010-07-18', 'end'=>'2010-08-15');
$dates[0] = array('start'=>'2010-07-01', 'end'=>'2010-08-31');

我怎么会从样品的输入到输出样本?

How could i go from the sample input to the sample output?


  1. 我试图改变为Joomla组件
  2. 的输出
  3. 我不是以英语为母语

  1. I'm trying to change the output of EventList a component for Joomla
  2. I'm not a native english speaker

所以,我再试一次:

如果该事件的开始日期比现在轻微那么相对于本次活动结束日期和事件顺序的其他事件朝九特派

if the event start date is minor than today then order the event relative to this event enddate and the others events startday

例如:

如果事件'A'上2010-07-01,终点开始2010-07-25和事件'B'开始于2010-07-24和当前日期为2010-07-20那么事件A 谈到事件发生后'B'

If the event 'A' started on 2010-07-01 and finish on 2010-07-25 and event 'B' starts on 2010-07-24 and the current date is 2010-07-20 then event 'A' comes after event 'B'

如果事件'A'开始于2010-07-20,终点在2010-07-25和事件'B'开始于2010-07-24和当前日期为2010-07-20那么事件'B 谈到事件发生后'A'

If the event 'A' starts on 2010-07-20 and finish on 2010-07-25 and event 'B' starts on 2010-07-24 and the current date is 2010-07-20 then event 'B' comes after event 'A'

我希望这是一个有点更清晰的了。

I 'hope' it's a little more clearer now.

推荐答案

嗯,所以,如果我理解正确:由星历排序如果> =今天,结束日期,如果开始日期< =今天

Hmmm, so if I understand correctly: sort by stardate if >=today, enddate if startdate <= today.

function _myDateSorter($a,$b){
    $date = date('Y-m-d');
    $adate = ($a['start'] >= $date) ? $a['start'] : $a['end'];
    $bdate = ($b['start'] >= $date) ? $b['start'] : $b['end'];
    if($adate =='0000-00-00') $adate = '9999-99-99';//sort after it appears
    if($bdate =='0000-00-00') $bdate = '9999-99-99';//sort after it appears
    if($adate == $bdate) return 0;
    return $adate > $bdate ? 1 : -1;
}

uasort($dates,'_myDateSorter');

这篇关于重新定位基于PHP的一个条件数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 19:58