<?php
$arr = [
// without first Dec, Jan and Jan lines:
// all subsequent lines are the current year
"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",
"Apr 12 23:07:39 hello",
"May 21 04:09:34 hello",
"Jun 7 23:34:56 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(
array_reverse(
preg_replace_callback(
'/^[a-z]{3} +\d+ \d\d:\d\d:\d\d/i',
function($m) {
static $lastStamp = null;
static $year = null;
$year ??= date('Y');
$currentStamp = date('m d H:i:s', strtotime($m[0]));
if ($currentStamp > ($lastStamp ?? $currentStamp)) {
--$year;
}
$lastStamp = $currentStamp;
return "$year $currentStamp";
},
array_reverse($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 12 23 21:37:56 hello',
1 => '2023 01 12 02:08:23 hello',
2 => '2023 01 16 17:34:33 hello',
3 => '2023 02 04 12:21:09 hello',
4 => '2023 03 19 17:07:26 hello',
5 => '2023 04 01 00:00:03 hello',
6 => '2023 04 12 23:07:39 hello',
7 => '2023 05 21 04:09:34 hello',
8 => '2023 06 07 23:34:56 hello',
9 => '2023 07 01 14:45:34 hello',
10 => '2023 08 13 11:37:23 hello',
11 => '2023 09 29 07:36:03 hello',
12 => '2023 10 30 09:01:00 hello',
13 => '2023 11 10 11:00:03 hello',
14 => '2023 12 25 21:47:51 hello',
)
preferences:
80.32 ms | 408 KiB | 5 Q