How can the fwrite function be effectively used with different game server strings in PHP?

When working with game servers in PHP, you may need to write different game server strings to a file using the fwrite function. To do this effectively, you can create an array of game server strings and then use a loop to write each string to the file. This approach allows you to easily manage and update the game server strings without duplicating code.

// Array of game server strings
$gameServers = [
    "Server 1",
    "Server 2",
    "Server 3"
];

// Open a file for writing
$file = fopen("game_servers.txt", "w");

// Write each game server string to the file
foreach ($gameServers as $server) {
    fwrite($file, $server . "\n");
}

// Close the file
fclose($file);