$fileName = "hello.txt"; $fileData = "Hello, world!"; file_put_contents($fileName, $fileData);
$fileName = "data.json"; $data = array( "name" => "John Doe", "email" => "johndoe@example.com", "age" => 25 ); $jsonData = json_encode($data); file_put_contents($fileName, $jsonData);
$fileName = "log.txt"; $logData = "New log entry"; file_put_contents($fileName, $logData, FILE_APPEND);Output: The file log.txt will be opened in append mode and the content "New log entry" will be appended to the end of the file. Package/Library: None required as the function is built-in to PHP.