How can the issue of displaying previous search results when selecting multiple source files be addressed in the PHP script?

Issue: The problem of displaying previous search results when selecting multiple source files can be addressed by implementing a mechanism to clear the search results each time a new file is selected. This ensures that only the search results relevant to the currently selected file are displayed. PHP code snippet:

<?php
// Clear previous search results
if(isset($_POST['selected_file'])) {
    // Code to clear previous search results
}

// Display search results for selected file
if(isset($_POST['selected_file'])) {
    $selected_file = $_POST['selected_file'];
    
    // Code to display search results for the selected file
}
?>