<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FSwitch-Statement%2FEnglish</id>
		<title>PHP-and-MySQL/C2/Switch-Statement/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FSwitch-Statement%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Switch-Statement/English&amp;action=history"/>
		<updated>2026-04-08T20:00:28Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Switch-Statement/English&amp;diff=521&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{|Border=1 !Time !Narration |- |0:00 |Hello and welcome to this PHP tutorial on the SWITCH statement. |- |0:10 |I'm going to show you a new exercise on this because its an import…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Switch-Statement/English&amp;diff=521&amp;oldid=prev"/>
				<updated>2012-11-29T06:30:17Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{|Border=1 !Time !Narration |- |0:00 |Hello and welcome to this PHP tutorial on the SWITCH statement. |- |0:10 |I&amp;#039;m going to show you a new exercise on this because its an import…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{|Border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:00&lt;br /&gt;
|Hello and welcome to this PHP tutorial on the SWITCH statement.&lt;br /&gt;
|-&lt;br /&gt;
|0:10&lt;br /&gt;
|I'm going to show you a new exercise on this because its an important feature of PHP&lt;br /&gt;
|-&lt;br /&gt;
|O:16&lt;br /&gt;
|Let's create the syntax quickly&lt;br /&gt;
|-&lt;br /&gt;
|0:20&lt;br /&gt;
|The SWITCH statement is a substitute for the IF statement. Its a lot more neater and formattable choice although the input is an expression.&lt;br /&gt;
|-&lt;br /&gt;
|0:38&lt;br /&gt;
|So, now let's input the value of something  and then let's save the value equal to this&lt;br /&gt;
|-&lt;br /&gt;
|0:45&lt;br /&gt;
|Then we can execute the code if it equals or matches this value&lt;br /&gt;
|-&lt;br /&gt;
|0:53&lt;br /&gt;
|It's not a comparison technique.  So, for comparing an IF statement for matching values and outputs that depend on the input, we're going to say SWITCH &lt;br /&gt;
|-&lt;br /&gt;
|1:03&lt;br /&gt;
|Let's start&lt;br /&gt;
|-&lt;br /&gt;
|1:05&lt;br /&gt;
|SWITCH  is the basic code for it&lt;br /&gt;
|-&lt;br /&gt;
|1:10&lt;br /&gt;
|Let's put an expression in here, for example, I will say Alex here&lt;br /&gt;
|-&lt;br /&gt;
|1:17&lt;br /&gt;
|Let's create a mini program and I will explain it as we go&lt;br /&gt;
|-&lt;br /&gt;
|1:20&lt;br /&gt;
|Just like the IFstatement we will put curly brackets here&lt;br /&gt;
|-&lt;br /&gt;
|1:26&lt;br /&gt;
|Now let's look at the way to call each sort of check &lt;br /&gt;
|-&lt;br /&gt;
|1:30&lt;br /&gt;
|We want to check the value here&lt;br /&gt;
|-&lt;br /&gt;
|1:33&lt;br /&gt;
|Now we will put this in quotation marks&lt;br /&gt;
|-&lt;br /&gt;
|1:37&lt;br /&gt;
|You can't even number obviously&lt;br /&gt;
|-&lt;br /&gt;
|1:42&lt;br /&gt;
|So what we type is - case - the value of the case that we want to match. For example- Alex&lt;br /&gt;
|-&lt;br /&gt;
|1:54&lt;br /&gt;
|Then we type a colon or a semi colon&lt;br /&gt;
|-&lt;br /&gt;
|1:58&lt;br /&gt;
|And then the condition if the case has matched with the SWITCH expression you have picked&lt;br /&gt;
|-&lt;br /&gt;
|2:05&lt;br /&gt;
|So, I will type - echo you have blue eyes&lt;br /&gt;
|-&lt;br /&gt;
|2:13&lt;br /&gt;
|To end our case comparison we're going to use break and a semi colon&lt;br /&gt;
|-&lt;br /&gt;
|2:20&lt;br /&gt;
|Remember that we've used the semi colon here but not here&lt;br /&gt;
|-&lt;br /&gt;
|2:25&lt;br /&gt;
|Now the second case. Lets see how to do it&lt;br /&gt;
|-&lt;br /&gt;
|2:30&lt;br /&gt;
|I'll type Billy and echo you have brown eyes&lt;br /&gt;
|-&lt;br /&gt;
|2:42&lt;br /&gt;
|Okay, and then break and semi-colon&lt;br /&gt;
|-&lt;br /&gt;
|2:47&lt;br /&gt;
|This is like an integrated IF. That is I could say - IF your name is Alex then echo you have blue eyes or ELSE IF your name is Billy you have brown eyes&lt;br /&gt;
|-&lt;br /&gt;
|3:00&lt;br /&gt;
|Probably for some people it's easy to do it this way. It's a lot more readable but it's a matter of choice&lt;br /&gt;
|-&lt;br /&gt;
|3:11&lt;br /&gt;
|Okay we got no more cases, I'm just going to use Alex and Billy for this example&lt;br /&gt;
|-&lt;br /&gt;
|3:20&lt;br /&gt;
|Here I will say default which will echo out - I don't know what color your eyes are&lt;br /&gt;
|-&lt;br /&gt;
|3:29&lt;br /&gt;
|Okay, we don't need a break after this because there are no more cases&lt;br /&gt;
|-&lt;br /&gt;
|3:38&lt;br /&gt;
|Obviously, there's no break after it cause there are no more options to chose from&lt;br /&gt;
|-&lt;br /&gt;
|3:43&lt;br /&gt;
|Okay, so, we've got our SWITCH here. Let's give it a go&lt;br /&gt;
|-&lt;br /&gt;
|3:48&lt;br /&gt;
|Now  I'm going to replace this ALEX here with a variable, to build our program&lt;br /&gt;
|-&lt;br /&gt;
|4:00&lt;br /&gt;
|So I type name equals, and I will let you decide that&lt;br /&gt;
|-&lt;br /&gt;
|4:05&lt;br /&gt;
|Then I'll say name, here&lt;br /&gt;
|-&lt;br /&gt;
|4:07&lt;br /&gt;
|So you see this is how we incorporate a variable here&lt;br /&gt;
|-&lt;br /&gt;
|4:11&lt;br /&gt;
|You should know how to do that by now&lt;br /&gt;
|-&lt;br /&gt;
|4:13&lt;br /&gt;
|So, let's start and see how this will work&lt;br /&gt;
|-&lt;br /&gt;
|4:18&lt;br /&gt;
|You'll say switch, you'll take this expression, which is equal to Alex&lt;br /&gt;
|-&lt;br /&gt;
|4:24&lt;br /&gt;
|Basically, this is the case which equals to Alex and it'll echo this.  The break is to end it&lt;br /&gt;
|-&lt;br /&gt;
|4:32&lt;br /&gt;
|And this is the case, Billy and it'll echo this and end with a break&lt;br /&gt;
|-&lt;br /&gt;
|4:39&lt;br /&gt;
|If the name is say, Rahul, the default will echo - I don't know what colour your eyes are&lt;br /&gt;
|-&lt;br /&gt;
|4:47&lt;br /&gt;
|Okay, so let's try running this&lt;br /&gt;
|-&lt;br /&gt;
|4:49&lt;br /&gt;
|Just to revise&lt;br /&gt;
|-&lt;br /&gt;
|4:52&lt;br /&gt;
|We can see that Alex matches to Alex matches to the output&lt;br /&gt;
|-&lt;br /&gt;
|4:57&lt;br /&gt;
|What you can do is you can enter as many lines of code here as you like.  This break determines where the case ends&lt;br /&gt;
|-&lt;br /&gt;
|5:05&lt;br /&gt;
|An IF statement needs curly brackets to end a block&lt;br /&gt;
|-&lt;br /&gt;
|5:12&lt;br /&gt;
|However, here break determines the end of the block. These are called blocks, by the way.&lt;br /&gt;
|-&lt;br /&gt;
|5:17&lt;br /&gt;
|So, let's change this to Billy and let's see what happens&lt;br /&gt;
|-&lt;br /&gt;
|5:22&lt;br /&gt;
|You have brown eyes - exactly what we determined here&lt;br /&gt;
|-&lt;br /&gt;
|5:28&lt;br /&gt;
|Okay, now I'll change this to Kyle.....and refresh, I don't know what colour your eyes are, because there is no block that states Kyle's eye colour in our program feature&lt;br /&gt;
|-&lt;br /&gt;
|5:45&lt;br /&gt;
|So, that's basically the SWITCH statement&lt;br /&gt;
|-&lt;br /&gt;
|5:47&lt;br /&gt;
|Try it out. Some people don't like using it, some prefer using it&lt;br /&gt;
|-&lt;br /&gt;
|5:50&lt;br /&gt;
|It's probably much faster than the IF statement. It's easier to control.  It looks a lot better.  So it's really up to your personal choice&lt;br /&gt;
|-&lt;br /&gt;
|5:56&lt;br /&gt;
|Thanks for watching.  This is Arvind for the Spoken Tutorial Project, signing off.  Goodbye.&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>