所以我有这个数组:
$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');
我有以下条件:
if an element 'start' is less then today, took the element's attribute 'end' and position the element relative to the others elements 'start'
因此,如果事件started yesterday
和ends tomorrow
出现在事件beginning today
所以生成的数组是这样的:
$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');
我怎么能从样本输入到样本输出?
[编辑]
所以,我会再试一次:
如果事件开始日期比今天小,那么相对于this event enddate
和others events startday
例如:
如果活动'A'在2010-07-01开始并在2010-07-25结束,活动'B'在2010-07-24开始,当前日期是2010-07-20,那么活动'A '在事件'B'之后出现
如果活动'A'在2010-07-20开始并在2010-07-25结束,活动'B'在2010-07-24开始,当前日期是2010-07-20,那么活动'B '在事件'A'之后出现。
我希望'现在更加清晰。
答案 0 :(得分:1)
嗯,所以,如果我理解正确的话:如果> =今天就按stardate排序,如果startdate< =今天则结束。
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');