What is the potential issue with the current code that randomly selects lines from the file?

The potential issue with the current code that randomly selects lines from the file is that it may select the same line multiple times, leading to duplicates in the output. To solve this issue, we can read all the lines from the file into an array, shuffle the array to randomize the order, and then select lines from the shuffled array without duplicates.

<?php
$file = 'data.txt';
$lines = file($file, FILE_IGNORE_NEW_LINES);
shuffle($lines);

$numLinesToSelect = 5;
$selectedLines = array_slice($lines, 0, $numLinesToSelect);

foreach ($selectedLines as $line) {
    echo $line . "\n";
}
?>