<?php
$arr = [
"Jan 12 02:08:23 hello",
"Dec 23 21:37:56 hello",
//"Jan 12 02:08:23 hello",
//"Jan 16 17:34:33 hello",
"Feb 4 12:21:09 hello",
"Mar 19 17:07:26 hello",
"Apr 1 00:00:03 hello",
"Nov 10 11:00:03 hello",
"Apr 12 23:07:39 hello",
"May 21 04:09:34 hello",
"Jun 7 23:34:56 hello",
"Sep 29 07:36:03 hello",
"Jul 1 14:45:34 hello",
"Aug 13 11:37:23 hello",
"Sep 29 07:36:03 hello",
"Oct 30 09:01:00 hello",
"Nov 10 11:00:03 hello",
"Dec 25 21:47:51 hello"
];
var_export(
preg_replace_callback(
'/^([a-z]{3}) +\d+/i',
function($m) {
static $lastMonthInt = 0;
static $year = null;
$year ??= date('Y', strtotime('-1 year'));
$currentMonthInt = date('n', strtotime($m[1]));
if ($currentMonthInt < $lastMonthInt) {
++$year;
}
$lastMonthInt = $currentMonthInt;
return "$year " . date('m d', strtotime($m[0]));
},
$arr
)
);
- Output for 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 => '2022 01 12 02:08:23 hello',
1 => '2022 12 23 21:37:56 hello',
2 => '2023 02 04 12:21:09 hello',
3 => '2023 03 19 17:07:26 hello',
4 => '2023 04 01 00:00:03 hello',
5 => '2023 11 10 11:00:03 hello',
6 => '2024 04 12 23:07:39 hello',
7 => '2024 05 21 04:09:34 hello',
8 => '2024 06 07 23:34:56 hello',
9 => '2024 09 29 07:36:03 hello',
10 => '2025 07 01 14:45:34 hello',
11 => '2025 08 13 11:37:23 hello',
12 => '2025 09 29 07:36:03 hello',
13 => '2025 10 30 09:01:00 hello',
14 => '2025 11 10 11:00:03 hello',
15 => '2025 12 25 21:47:51 hello',
)
preferences:
83.51 ms | 408 KiB | 5 Q