I've been trying for two days to create an array from a text file list, shuffle it, then rewrite the text file using file_put_contents.
I've succeeded in doing so BUT when I run the script more than once it creates multiple and random spaces between each item.
I've tried many different ideas but no joy yet.
Below is my code.
<?php
// create array from text file
$array = file('list.txt');
// shuffle the array
shuffle ($array);
// overwrite original with new shuffled text file
file_put_contents('list.txt', implode(PHP_EOL, $array));
?>