25 lines
521 B
PHP
25 lines
521 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
function sortDueWords(array $words): array
|
|
{
|
|
$today = date('Y-m-d');
|
|
|
|
usort($words, function ($a, $b) use ($today) {
|
|
|
|
$aDue = $a['nextReview'] ?? '1970-01-01';
|
|
$bDue = $b['nextReview'] ?? '1970-01-01';
|
|
|
|
$aPriority = ($aDue <= $today) ? 0 : 1;
|
|
$bPriority = ($bDue <= $today) ? 0 : 1;
|
|
|
|
if ($aPriority !== $bPriority) {
|
|
return $aPriority <=> $bPriority;
|
|
}
|
|
|
|
return strcmp($aDue, $bDue);
|
|
});
|
|
|
|
return $words;
|
|
} |