How can error messages be displayed as pop-ups in PHP applications?

To display error messages as pop-ups in PHP applications, you can use JavaScript's alert function to create a pop-up dialog box that shows the error message to the user. This can be useful for providing immediate feedback on errors or validation issues.

<?php
// Check for errors
if($error){
    echo "<script>alert('Error: $error');</script>";
}
?>