php - Sorting dates with months or days on 0 -


i have sort dates on php, in of them can have '0' on month or day, example:

1951-11-00

1951-12-14

problem dates don't sorted other dates have year, day , month values.

first tried using array_multisort:

    foreach ($objects $key => $part) {         $sort[$key] = strtotime($part['object']['date']);     }     array_multisort($sort, sort_desc, $objects ); 

it sort ok, first sorts values have 00 on month or day, , sort normal dates, example:

1937-05-00

1937-04-00

1935-11-00

1951-12-16

1951-12-14

as see, order not ok, because dates 1951 should go first, sort algorithm classifying dates in 2 groups, ones have 00, , ones have full numbers.

then tried uasort, i'm not getting results.

how can sort dates correctly? list put, need show on order (regardless of having month on 00):

1951-12-16

1951-12-14

1937-05-00

1937-04-00

1935-11-00

just sort them strings. in comparable format when compared strings.

$dates = [     '1937-05-00',     '1937-04-00',     '1935-11-00',     '1951-12-16',     '1951-12-14' ];  usort($dates, function($a, $b) {     return $a < $b; });  var_export($dates); 

demo


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -