I'm trying to output the last 6 lines of a .txt file in reverse order.
So if the file consists of this:
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
I wan't it to output:
line10
line9
line8
line7
line6
line5
I can get it to putput the 6 lines in "normal" order just fine, but are having problems reversing it.
This is my code: I tried using $i-- but with no luck:
$file = file("logs/accesslog.txt"); for ($i = count($file)-6; $i < count($file); $i++) { echo $file[$i] . "<br>"; }
I would very much prefer not to use array_reverse() function, as the above script is used in quite a few different functions across my site, and modifying this would mean to modify them all.
How could I modify it to reverse the output?