How can the use of flush() affect the output of PHP code in this context?

Using flush() in PHP can help to improve the output of long-running scripts by sending data to the browser before the script has finished executing. This can be particularly useful when generating large amounts of data or when you want to provide feedback to the user during script execution. By using flush(), you can ensure that the user sees output in real-time rather than waiting for the script to finish.

<?php

// Generate some data
for ($i = 0; $i < 10; $i++) {
    echo "Processing item $i...<br>";
    flush();
    // Simulate some processing time
    sleep(1);
}

echo "Script execution complete.";

?>