The exit() function is used to stop the execution of PHP script.
In PHP, you can stop the execution of a script using the exit() or die() functions. Both functions immediately terminate the script’s execution and can be used with or without a message.
Here’s how you can use them:
php
// Using exit() exit("Script execution stopped.");
// Using die() die("Script execution stopped.");
Both exit() and die() functions are interchangeable, and they serve the same purpose. They can be particularly useful for error handling or terminating a script under certain conditions.