我正在尝试按日期DESC订购从CSV读取的事件并将其打印在DIV中。该文件必须被读取直至其结束,然后按日期DESC仅按以下类别中的条目排序: champions 和 euro 。
这是我写的代码,也检查了StackOverflow上的一个线程,但我无法对结果进行排序。任何帮助将非常感谢!
$today = date('Y-m-d', strtotime("now"));
$header = fgetcsv($handle);
$length = 1000;
$delimiter = ";";
$date = array();
$rows = array();
while ( ( $row = fgetcsv($handle, $length, $delimiter) ) != FALSE) {
if( ($row[2] == "champions" || $row[2] == "euro") ) {
// if there is a , in the date take the first part of it
preg_match('~([^\s]+)(?:,.*)?$~', $row[3], $m); // This is probably wrong (preg_match drives me crazy)
$date[] = $m[1];
$rows[] = $row;
}
}
fclose($handle);
array_multisort($date, $rows);
foreach ($rows as $entry) {
$csv_date = date('Y-m-d', strtotime($entry[3]));
if($csv_date >= $today) {
if( ($i == 0 || $i <= 2) ) {
echo date('M. ' . 'Y', strtotime($entry[3])) . "<br/>";
echo date('d', strtotime($entry[3])) . "<br/>";
echo "<br/>";
// Print only 3 matches
echo $entry[8];
$i++;
}
}
}