我想知道一种很好的方法来检查数组中哪个元素是按开始/结束日期排列的第一个元素(具有优先级)。
例如,这里是数组:
(
[0] => Array
(
[ID] => 16
[begin_date] => DateTime Object
(
[date] => 2016-01-01
[timezone_type] => 3
[timezone] => UTC
)
[end_date] => DateTime Object
(
[date] => 2016-11-30
[timezone_type] => 3
[timezone] => UTC
)
)
[1] => Array
(
[ID] => 33
[begin_date] => DateTime Object
(
[date] => 2015-01-04
[timezone_type] => 3
[timezone] => UTC
)
[end_date] => DateTime Object
(
[date] => 2016-02-29
[timezone_type] => 3
[timezone] => UTC
)
)
)
在这种情况下,第二个元素具有优先级。因为它的开始日期早于第一个元素的开始日期。而且,它的结束日期仍在未来。
条件:
- 如果begin_date在将来,则它不能是前导元素
- 如果end_date已过期(如果today>end_date),则前导
元素必须是具有最新end_date的元素
提前感谢!
uasort($memberArray,function($a,$b){
$c = $a['begin_date']['date'] - $b['begin_date']['date';
$c .= $a['overall']['PD'] - $b['overall']['PD'];
$c .= $a['overall']['PF'] - $b['overall']['PF'];
$c .= $a['overall']['W'] - $b['overall']['W'];
$c .= $a['overall']['MP'] - $b['overall']['MP'];
return $c;
});