What is the purpose of the "finally" block in PHP exception handling?

The purpose of the "finally" block in PHP exception handling is to provide a section of code that will always be executed, regardless of whether an exception is thrown or not. This can be useful for cleaning up resources or performing final actions that need to occur regardless of the outcome of the try-catch block.

try {
    // Code that may throw an exception
    throw new Exception("An error occurred");
} catch (Exception $e) {
    // Handle the exception
    echo "Exception caught: " . $e->getMessage();
} finally {
    // Code that will always be executed
    echo "Finally block executed";
}