排序PHP自定义数据数组

排序PHP自定义数据数组,php,arrays,sorting,Php,Arrays,Sorting,我需要将此列表按下一个即将到来的日期排序到最远的日期。我试过很多我数不清的东西 对列表进行排序的正确方法是什么 array(13) { [9]=> string(16) "Jun 30 - Tuesday" [8]=> string(16) "Jun 23 - Tuesday" [10]=> string(16) "Jul 07 - Tuesday" [11]=> string(17) "Jun 25 - Thursday" [12]=

我需要将此列表按下一个即将到来的日期排序到最远的日期。我试过很多我数不清的东西

对列表进行排序的正确方法是什么

array(13) {
  [9]=>
  string(16) "Jun 30 - Tuesday"
  [8]=>
  string(16) "Jun 23 - Tuesday"
  [10]=>
  string(16) "Jul 07 - Tuesday"
  [11]=>
  string(17) "Jun 25 - Thursday"
  [12]=>
  string(17) "Jul 02 - Thursday"
  [7]=>
  string(15) "Jul 06 - Monday"
  [6]=>
  string(18) "Jul 01 - Wednesday"
  [2]=>
  string(15) "Jun 26 - Friday"
  [1]=>
  string(15) "Jul 05 - Sunday"
  [3]=>
  string(15) "Jul 03 - Friday"
  [4]=>
  string(18) "Jun 24 - Wednesday"
  [5]=>
  string(15) "Jun 29 - Monday"
  [0]=>
  string(15) "Jun 28 - Sunday"
}
不妨使用和

使用usort docs页面上的第一个示例作为模板,您可以执行以下操作:

function compare_dates( $a, $b ) {
    return strtotime( $a ) < strtotime( $b ) ? -1 : 1;
}
usort( $your_array_of_dates, 'compare_dates' );
函数比较日期($a,$b){ 返回strotime($a)
希望有帮助

我想我已经明白了

function sortFunction( $a, $b ) {
    $a = explode(" - ",$a);
    $a = $a[0];
    $b = explode(" - ",$b);
    $b = $b[0];
    return strtotime($a) - strtotime($b);
}
usort($allStartDateTime, "sortFunction");

你的方式似乎没有正确分类。我在上面贴了一个答案,看起来确实有效。