How to stop the execution of a PHP script?

Use the exit() function to stop a PHP script. You can also write die(), it works exactly same. Any code after it will not run.

<?php
echo "Start<br>";

exit("Stopped here");

echo "This line never runs";
?>

Output:

Tutorials Class - Output Window

Start
Stopped here

To stop only a loop, use break instead. A full explanation is in PHP exit() function.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.