如何在PHP中保存文件时迭代文件名?

I am new in PHP and still learning about it. This time i want to print some text and save in a file. But i want the file names to be automatically changed.

For example file1.txt, file2.txt, file3.txt, and so on. Here's my code so far:

$read = file("example.txt",FILE_IGNORE_NEW_LINES);
$newFile = "file_1.txt";
$of = fopen($newFile,'w');
foreach($read as $k => $file){
    $line = explode(" ",$file);
    $line2 = array_slice($line,0,3);
    foreach($line2 as $value){
        echo $value." ";
        fwrite($of,$value." ");
    }
    echo "<br>";
    fwrite($of,"
");

}
fclose($of);
$read = file("example.txt",FILE_IGNORE_NEW_LINES);

$filesToWrite = ["file_1.txt", "file_2.txt","file_3.txt"];
foreach($filesToWrite as $fileToWrite){
    $of = fopen($fileToRead,'w');
    foreach($read as $k => $file){
        $line = explode(" ",$file);
        $line2 = array_slice($line,0,3);
        foreach($line2 as $value){
            echo $value." ";
            fwrite($of,$value." ");
        }
        echo "<br>";
        fwrite($of,"
");

    }
}
fclose($of);

I hope help you!