What are some alternative methods to storing and accessing the current line number when sequentially outputting lines from a text file in PHP?

When sequentially outputting lines from a text file in PHP, one alternative method to storing and accessing the current line number is to use a counter variable that increments with each line processed. This counter can be used to keep track of the current line number being outputted.

$file = fopen("example.txt", "r");
$lineNumber = 1;

while(!feof($file)) {
    $line = fgets($file);
    echo "Line " . $lineNumber . ": " . $line;
    $lineNumber++;
}

fclose($file);