What is the difference between using "rw" and "w+" or "r+" in the fopen function in PHP?

When using the fopen function in PHP, "rw" opens the file for reading and writing, but if the file does not exist, it will fail. On the other hand, "w+" and "r+" modes will create the file if it doesn't exist and open it for reading and writing. "w+" will truncate the file to zero length, while "r+" will not truncate the file.

// Using "w+" mode to open a file for reading and writing
$file = fopen("example.txt", "w+");
if ($file) {
    // File operations here
    fclose($file);
} else {
    echo "Error opening file.";
}