Created a variable called $file. This variable contains the name of the file that we want to create.
Using PHP’s is_file function, we check to see if the file already exists or not.
If is_file returns a boolean FALSE value, then our filename does not exist.
If the file does not exist, we create the file using the function file_put_contents.
//The name of the file that we want to create if it doesn't exist.
$file = 'test.txt';
//Use the function is_file to check if the file already exists or not.
if(!is_file($file)){
//Some simple example content.
$contents = 'This is a test!';
//Save our content to the file.
file_put_contents($file, $contents);
}