What are the differences between using absolute and relative file paths in PHP functions like fwrite()?

When using functions like fwrite() in PHP, it's important to understand the differences between absolute and relative file paths. Absolute file paths specify the full path from the root directory, while relative file paths specify the path relative to the current working directory. When using fwrite(), it's generally safer to use absolute file paths to ensure that the file is written to the correct location regardless of the current working directory.

// Using absolute file path in fwrite()
$file = '/path/to/file.txt';
$data = 'Hello, World!';
fwrite(fopen($file, 'w'), $data);