<?php
$array = [
'2022-06-30',
'2022-04-20',
'2021-04-07',
'2022-09-09',
'2022-03-08',
'2021-08-07',
'2022-10-12'
];
$today = '2022-06-02'; // date('Y-m-d');
usort($array, fn($a, $b) => ($a > $today && $b > $today ? -1 : 1) * ($a <=> $b));
var_export($array);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
0 => '2021-04-07',
1 => '2021-08-07',
2 => '2022-03-08',
3 => '2022-04-20',
4 => '2022-10-12',
5 => '2022-09-09',
6 => '2022-06-30',
)
- Output for 5.6.40
- Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/GNZHh on line 15
Process exited with code 255.
preferences:
115.97 ms | 407 KiB | 5 Q