使用PHP以相反的顺序显示CSV行

Trying to get this code to echo the rows it gets from the CSV file in reverse order. Any idea how to do this?

<?php
$row = 1;
$FILE = "file.csv";

if (($handle = fopen($FILE, "r")) !== FALSE) {

    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);

        for ($c=0; $c < $num; $c++) {
            if ($c == 0) $first = $data[$c];
            if ($c == 1) $second = $data[$c];

        }

    }
    fclose($handle);

}
?>

Create a specific function for this task and call the function. It is always easier to split your program into smaller pieces. You need to read the data into an array and the reverse the order.

<?php
function loadCSV($file) {
    $rows = array();

    if (($handle = fopen($file, "r")) !== FALSE) {

        while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
            array_push($rows, $data);
        }
        fclose($handle);
    }

    return array_reverse($rows);
}
?>

Here is how to use this function:

<?php
$data = loadCSV('data.csv');
print_r($data);
?>