So, I have a sidebar.php that is included in the index.php
. Under a certain condition, I want sidebar.php
to stop running, so I thought of putting exit
in sidebar.php
, but that actually exits all the code beneath it meaning everything beneath include('sidebar.php');
in index.php
all the code would be skipped as well. Is there a way to have exit
only skip the code in the sidebar.php
?
The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script.
If you started it in background use ps aux | grep time. php to get PID. Then just kill PID . If process started in foreground, use to interrupt it.
You have to type ctrl + C to exit.
You can't break if statements, only loops like for or while. If this if is in a function, use 'return'.
Just use return;
Do also be aware that it is possible to actually return something to a calling script in this way.
if your parent script has $somevar = include("myscript.php");
and then in myscript.php you do say... return true;
you will get that value in $somevar
Yes, you just use return;
. Your sidebar.php file might look something like this:
<?php if($certain_condition) { return; } else { // Do your stuff here } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With