How can one make fwrite binary-safe in PHP when saving data like in C++?

When using fwrite in PHP to save binary data, it's important to open the file in binary mode ('b') to ensure that the data is written as-is without any encoding or translation. This will make fwrite binary-safe and prevent any unexpected modifications to the data.

$file = fopen('data.bin', 'wb');
$data = "\x00\x01\x02\x03"; // binary data to write
fwrite($file, $data);
fclose($file);