What is the importance of using fclose() after fopen() and fwrite() in PHP file handling?

It is important to use fclose() after using fopen() and fwrite() in PHP file handling to properly close the file handle and release any resources associated with it. Failure to close the file handle can lead to memory leaks and potential issues with file locking. By using fclose(), you ensure that the file is properly closed and any changes made with fwrite() are saved.

$file = fopen("example.txt", "w");
fwrite($file, "Hello, World!");
fclose($file);