<?php
$format = 'Год: Y, Месяц: m, День: d';
$dates = [new DateTime('2020-10-20'), new DateTime('2000-02-05'), new DateTime('2000-02-02'), new DateTime('2000-05-01')];
usort($dates, fn($a, $b) => $a < $b ? -1: 1);
foreach($dates as $date) {
var_dump($date->format($format));
}
var_dump('Min: ' . $dates[0]->format($format));
var_dump('Max: ' . $dates[count($dates) - 1]->format($format));
- Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
- string(42) "Год: 2000, Месяц: 02, День: 02"
string(42) "Год: 2000, Месяц: 02, День: 05"
string(42) "Год: 2000, Месяц: 05, День: 01"
string(42) "Год: 2020, Месяц: 10, День: 20"
string(47) "Min: Год: 2000, Месяц: 02, День: 02"
string(47) "Max: Год: 2020, Месяц: 10, День: 20"
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(42) "Год: 2000, Месяц: 02, День: 02"
string(42) "Год: 2000, Месяц: 02, День: 05"
string(42) "Год: 2000, Месяц: 05, День: 01"
string(42) "Год: 2020, Месяц: 10, День: 20"
string(47) "Min: Год: 2000, Месяц: 02, День: 02"
string(47) "Max: Год: 2020, Месяц: 10, День: 20"
- Output for 7.3.0 - 7.3.33
- Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/sVdO8 on line 7
Process exited with code 255.
preferences:
137.78 ms | 401 KiB | 153 Q