The method I showed in the previous thread of - parse the data at the earliest point, then operate on the parsed data, was to allow you to operate on the data as a set, using php array functions, instead of creating a bespoke solution for each different operation.
Doing this for the current operation, would mean adding a few lines to the _parse() call-back function to produce a sortable date column, sorting the data on the sortable date column, then getting the earliest entry -
$file = 'somefile.txt';
$data = file($file, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
// call-back function to parse each line of data into an array
function _parse($line)
{
$arr['date'] = substr($line,0,10);
// make a sortable date column
$parts = explode('/',$arr['date']);
// original is apparently - dd/mm/yyyy
$arr['sdate'] = "$parts[2]-$parts[1]-$parts[0]";
$arr['code'] = substr($line,11,2);
// the rest of this doesn't seem to match the current example line format
/*
$p = strpos($line, ')');
$arr['title'] = substr($line, 14, $p-13);
$parts = explode(' ',substr($line, $p+2));
$arr['file'] = $parts[0];
$arr['location'] = implode(' ',array_slice($parts,1));
*/
return $arr;
}
// parse the data at the earliest point, then operate on the parsed data
$data = array_map('_parse',$data);
// sort by the 'sdate' sortable date column
usort($data, fn($a, $b)=>$a['sdate']<=>$b['sdate']);
// get the zeroth entry, earliest date
$earliest = $data[0];
// examine the result
echo '<pre>'; print_r($earliest); echo '</pre>';