How to not only break from switch statement but exit program?

Hi,
I am querying a database, running a switch statement and should the variable equal a couple of the possibilities, leave the switch and exit the program, otherwise leave the switch but continue on through the program.

With regards to the code below:
For values: "Not Banned" and "Slow Down" I want it to leave the switch and continue on (works fine).

But for "Busy Signal" and "Reject Call", I'm trying to get it to do what is in the case and then just exit the whole thing. What is happening is it executes the element in the case statement but continues on. How do I kill the program just for those two possibilities?

 
// Check for Ban
$result = mysql_query("SELECT Phone FROM ban WHERE Number_noformat = '$FromCaller' AND account_id = '$account_id' LIMIT 1");

if(mysql_num_rows($result)!=0){
	while ($row = mysql_fetch_assoc($result)) {
	$phoneban = $row["Phone"];
	
	switch ($phoneban){
	
		case "Not Banned":
		break;
		
		case "Slow Down":?>
		<Pause length="12"/>
		<?php
		break;
	
		case "Busy Signal":?>
		<Reject reason="busy" />
		<?php
		break;
	
		case "Reject Call":?>
		<Reject />
		<?php
		break;
		}
		
}
}

Open in new window


*Lastly any suggestions how to improve my code are always welcome :)
LVL 1
tjyoungAsked:
Who is Participating?
 
Lukasz ChmielewskiCommented:
just use exit(); instead of break;
0
 
eriksmtkaCommented:
the php function "exit()" actually stops the script from processing further instructions
0
 
tjyoungAuthor Commented:
thanks I didn't realize you can swap out break with exit
0
 
eriksmtkaCommented:
suggested improvement...

i don't usually break out of PHP to print text.. especially in case like this where you don't have much to print anyway and formatting isn't really necessary...

switch ($phoneban){
	
		case "Not Banned":
		break;
		
		case "Slow Down":
                echo '<Pause length="12">';
		break;
	
		case "Busy Signal":
		echo '<Reject reason="busy" />';
		break;
	
		case "Reject Call":
		echo '<Reject />';
		break;
		}

Open in new window


Also.. the use of switch/case is kind of a religious argument.  A lot of people don't like them, i for don't have an opinion, but using if/elseif/then is perfectly acceptable:

if ($phoneban == "Not Banned") {
...
} elseif ($phoneban == "Slow Down") {
...
} elseif ($phoneban == "Busy Signal") {
...
} elseif ($phoneban == "Reject Call") {
...
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.