<?php
$arr = [
"Dec 23 21:37:56 hello",
"Jan 12 02:07:23 hello",
"Jun 3 23:34:34 hello",
"Dec 25 12:47:51 hello"
];
var_export(
preg_replace_callback(
'/^([a-z]{3}) +\d+/i',
function($m) {
static $encounteredJan = false;
$encounteredJan = $encounteredJan || $m[1] === 'Jan';
return date('Y m d', strtotime($m[0] . ($encounteredJan ? '' : ' -1 year')));
},
$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:07:23 hello',
2 => '2023 06 03 23:34:34 hello',
3 => '2023 12 25 12:47:51 hello',
)
preferences:
88.02 ms | 407 KiB | 5 Q