What are the different file opening modes in PHP and how do they affect file creation?

When opening files in PHP, there are different modes that can be specified which determine how the file is opened and what operations can be performed on it. The most common file opening modes include "r" for reading, "w" for writing (and truncating the file to zero length), "a" for writing (appending to the end of the file), and "x" for creating and writing to a new file. These modes affect file creation by determining whether a new file is created, whether existing files are overwritten, and whether the file pointer is positioned at the beginning or end of the file.

// Example of opening a file in write mode to create a new file
$file = fopen("example.txt", "w");
fclose($file);