How can the flush() function in PHP be used to improve the loading speed of dynamically included files?

When dynamically including files in PHP, the content of the included files is usually buffered until the script finishes executing. This can lead to slower loading times, especially for large files. By using the flush() function in PHP, we can send the output to the browser immediately instead of waiting for the script to finish, thus improving the loading speed of dynamically included files.

ob_start(); // Start output buffering

// Dynamically include files
include 'file1.php';
include 'file2.php';
include 'file3.php';

ob_end_flush(); // Flush the output buffer