What is the significance of using the correct stream resource in PHP functions like fwrite() and fclose()?

Using the correct stream resource in PHP functions like fwrite() and fclose() is crucial because these functions operate on specific file handles or resources. If the wrong resource is used, it can result in errors or unexpected behavior. To ensure the correct stream resource is used, it is important to properly open the file using fopen() and store the resource in a variable to be used in subsequent file operations.

$filename = "example.txt";
$file = fopen($filename, "w");

if ($file) {
    fwrite($file, "Hello, World!");
    fclose($file);
} else {
    echo "Unable to open file.";
}