WEBVTT

00:00.440 --> 00:03.530
I will call you back again to add a video lecture in PHP.

00:03.530 --> 00:09.920
And in this video lecture we go ahead and look at switch statement in PHP.

00:16.610 --> 00:24.440
So switch statement is another type of decision making statement in PHP that is used to compare one

00:24.440 --> 00:28.430
value with bunch of other values in your program.

00:28.430 --> 00:32.270
So you can have so many switch cases.

00:32.270 --> 00:38.060
And in some statements it uses these two keywords switch and cases.

00:38.060 --> 00:39.200
We add a switch.

00:39.200 --> 00:48.590
We actually do the job of uh showing you the, the variable.

00:48.920 --> 00:50.750
And then the case.

00:50.750 --> 00:55.430
We actually give you the values which are going to compare.

00:55.430 --> 00:57.410
So you have the switch.

00:57.440 --> 00:59.840
Then you have so many cases to compare.

00:59.840 --> 01:06.950
So once you set the variable inside the switch, then you go ahead and begin to compare different different

01:06.950 --> 01:07.400
cases.

01:07.400 --> 01:13.340
So you won't have case one, case two three, four to as many possible cases as you want.

01:13.370 --> 01:15.890
Now let me go ahead and use maybe the football.

01:15.920 --> 01:23.210
Maybe if we insert remove and it's going to say uh escort that goes under or let's go ahead and use

01:23.210 --> 01:27.320
something very simple and very, uh, unique like the students grid.

01:27.320 --> 01:29.720
So first of all, I'll create a form for this.

01:29.750 --> 01:31.280
We want to say form.

01:31.280 --> 01:34.580
And then we go ahead and close this.

01:34.580 --> 01:39.020
And then let's go ahead and uh, put in action.

01:39.020 --> 01:42.800
And that is going to be site that PHP.

01:42.920 --> 01:48.110
And then we'll go ahead and say mytouch and let the method be post method.

01:48.110 --> 01:50.930
And then we go ahead and create a form.

01:50.930 --> 01:58.670
And let the form we create is going to be a form that's going to ask students for their grid to understand.

01:58.850 --> 01:59.810
what I'm going to say?

02:01.070 --> 02:02.420
In such great.

02:05.390 --> 02:06.080
So.

02:06.080 --> 02:06.950
In such great.

02:06.950 --> 02:16.100
And then go ahead and put the grid so inputs and the, the type of the input is going to be just text.

02:17.510 --> 02:25.940
So and let the method which are going to use here is okay I might say method let name.

02:25.940 --> 02:30.500
So let name be equal to grid.

02:30.890 --> 02:31.430
All right.

02:31.430 --> 02:33.350
So go ahead and close this.

02:33.350 --> 02:37.190
And let's go ahead and impute our submit button.

02:37.190 --> 02:43.940
So input type and the input type be submit.

02:44.330 --> 02:44.750
All right.

02:44.750 --> 02:46.850
So I'm trying to write submit.

02:47.720 --> 02:49.430
Now go ahead and close this.

02:49.430 --> 02:52.430
And if we go on go ahead and refresh this.

02:52.460 --> 02:54.470
We have our inset grid.

02:54.470 --> 02:57.140
And then go ahead and submit that.

02:57.350 --> 02:58.550
So I hope that is good.

02:58.550 --> 03:01.310
So let's go ahead and just put in Greek.

03:01.340 --> 03:03.380
I just want this to be short.

03:03.380 --> 03:04.610
So go ahead and save.

03:04.640 --> 03:05.270
Great.

03:05.270 --> 03:06.890
And save this and refresh.

03:06.890 --> 03:08.330
We have great input.

03:08.330 --> 03:08.660
Great.

03:08.660 --> 03:10.640
We go ahead and submit that.

03:10.640 --> 03:17.030
Now if I try to go right in here and create move ahead and create a.

03:20.150 --> 03:23.330
A variable and let variable be equal to.

03:23.360 --> 03:29.630
Let me see if we go ahead and see posts.

03:29.870 --> 03:37.100
And then we go ahead and say grid because I think in the grid right in here, go ahead and place semicolon

03:37.100 --> 03:37.850
at the end.

03:37.850 --> 03:40.640
And then we go ahead and execute this.

03:40.640 --> 03:47.240
So we go ahead and echo whatever the user puts in there.

03:47.240 --> 03:50.510
So with semicolon at the end and let's save this.

03:50.510 --> 03:52.220
Now go ahead and refresh this.

03:52.220 --> 03:55.760
And uh this arrow always cool.

03:55.790 --> 04:00.920
Now if you want this error to stall, this is not an error from your computer.

04:00.920 --> 04:02.210
If I go ahead, I click a submit.

04:02.240 --> 04:03.650
This error will actually go out.

04:03.680 --> 04:05.840
You see that if I click on this it goes out.

04:05.870 --> 04:07.400
What if you don't want to do that.

04:07.400 --> 04:10.880
You go ahead and put PHP error or put in.

04:10.910 --> 04:16.130
You understand and let the error button be equal to zero and it will no longer do that.

04:16.130 --> 04:22.400
So let me go ahead and say we have a A and if you submit it's going to print out A.

04:22.430 --> 04:29.120
If you have B it's going to print out B, if you have C it's going to print out C.

04:29.150 --> 04:36.890
Now what to tell you, the user whenever you insert A is going to see you have an A or you have an A

04:37.190 --> 04:37.730
grade.

04:38.690 --> 04:40.850
So how can we be able to do that.

04:41.270 --> 04:45.200
Because these this code and one can not be able to do that for us.

04:45.200 --> 04:49.520
So in order to do that I'm going to remove whatever we have right in here.

04:49.520 --> 04:53.780
And let's go ahead and write a switch statement.

04:53.780 --> 04:58.910
So First of all, I'll go back to paste this.

04:58.940 --> 05:01.160
I'll go ahead and remove the echo.

05:01.190 --> 05:05.420
Then I'm going to put the echo right inside the switch statement I'm going to create.

05:05.420 --> 05:07.670
So go ahead and say switch.

05:07.670 --> 05:13.040
And you see when I click on switch the first one I have is the variable which is this variable here.

05:13.070 --> 05:17.480
Like I told you the variable is the first thing you insert into the switch.

05:17.630 --> 05:19.340
So great.

05:19.370 --> 05:22.250
Now it has created some cases for you.

05:22.250 --> 05:23.510
And then the default.

05:23.540 --> 05:26.150
The default is the last of all days.

05:26.150 --> 05:31.610
So if all the cases are not met then it goes on to print out the default.

05:31.610 --> 05:38.180
So if it fails to get anything from the value from the cases, then it will actually print out the default.

05:38.210 --> 05:39.110
You understand.

05:39.140 --> 05:44.900
Now let's go ahead and see case which is how this case holds the value.

05:44.900 --> 05:48.560
So let me say this is an A you understand.

05:48.560 --> 05:54.920
And it goes on to echo out the migraine and say Echo.

05:54.950 --> 05:58.250
And it's good to see you.

05:58.610 --> 06:02.600
Have you have an.

06:06.020 --> 06:09.920
Excellent grade.

06:09.950 --> 06:10.370
All right.

06:10.370 --> 06:14.060
So anyone that has an A we always have an excellent grade.

06:14.090 --> 06:16.070
Now I'll go ahead and copy this.

06:16.160 --> 06:25.100
So now what it break does is that if it checks a it will actually break out from A and then check B.

06:25.130 --> 06:28.250
And in that way it will check all of them.

06:28.400 --> 06:29.420
Let's go ahead and paste that.

06:29.420 --> 06:32.210
So can you to understand explain that better.

06:32.210 --> 06:34.910
So I inserted another one.

06:36.410 --> 06:44.000
And uh so let's go ahead and insert this one then the next one.

06:46.220 --> 07:01.790
So this is case b and c and c case b and uh, c and uh d now the A says you have an excellent grade.

07:01.820 --> 07:06.350
The B is going to be you have an amazing grade.

07:06.380 --> 07:17.690
The C is going to be you have a good grade then the D is going to be you have a Fe Great Dane.

07:20.360 --> 07:24.710
The E is going to be you have.

07:26.090 --> 07:27.410
Let me say you have a bad grade.

07:28.610 --> 07:29.030
All right.

07:29.060 --> 07:34.220
So the last one is going to be your failed.

07:35.570 --> 07:36.410
So.

07:40.280 --> 07:41.510
You've heard.

07:41.750 --> 07:48.410
So now if it checks all these grades and it didn't get anything.

07:48.440 --> 08:00.740
Now what happens is that it goes to default and it's going to echo, as I say, echo invalid.

08:01.760 --> 08:02.360
Great.

08:02.390 --> 08:03.950
Now let me go ahead and explain all this.

08:03.980 --> 08:06.320
Let me go ahead and explain what we just did right in here.

08:06.380 --> 08:09.890
Now for the switch cases it checks on.

08:09.920 --> 08:18.020
We create a switch and we pass in the variable grid, which gets whatever inputs the user in certain

08:18.020 --> 08:21.560
right inside this, uh, form.

08:21.560 --> 08:26.360
So and then the name is grid and that is what we inserted inside.

08:26.390 --> 08:28.880
Or we save inside this variable called grid.

08:28.880 --> 08:31.520
And now we begin to check the input.

08:31.520 --> 08:34.760
So if a user inserts E we're going to echo out.

08:34.760 --> 08:36.290
You have an excellent grid.

08:36.290 --> 08:41.600
And if we check and the user didn't insert a we break out of this case.

08:41.600 --> 08:46.220
So you can see I added breaks in every one of the cases.

08:46.220 --> 08:52.670
So whenever it checks a case and the case didn't meet up or it will not remain there, it will break

08:52.700 --> 08:54.260
out and move to the next one.

08:54.260 --> 09:02.030
So when it checks all of these cases and it did not meet any one, it goes on and say invalid grid.

09:02.060 --> 09:04.580
Now let's go ahead and save this.

09:04.580 --> 09:07.700
I'm going to refresh this guy on a fresh.

09:07.700 --> 09:10.940
You have an excellent grid because I inserted an A.

09:10.970 --> 09:18.980
So if I put in F and submit invalid because here I select the A right in here.

09:18.980 --> 09:20.450
So I've changed that to F.

09:20.450 --> 09:22.400
And now I will replace this.

09:22.400 --> 09:24.290
And the default.

09:24.320 --> 09:25.070
You see that.

09:25.070 --> 09:29.750
So if I insert e and submit you have a bad grid.

09:29.780 --> 09:39.620
You if you insert a D it says you have, oh this should be a fake grid and not a.

09:39.620 --> 09:39.980
All right.

09:40.010 --> 09:46.070
So I didn't change all these things shall be good amazing and excellent and so on.

09:46.310 --> 09:47.720
Let's go ahead and check it out.

09:47.750 --> 09:57.390
Now let's go ahead and add Z and submit invalid grade, so the grade ranges from A to F, and anything

09:57.420 --> 10:05.160
apart from D is an invalid grade, so you can actually use the if else if statement to do this.

10:05.190 --> 10:14.040
But you can see that this is more shorter, more simple and uh, more clear to developers than the if

10:14.070 --> 10:15.270
else statement.

10:15.270 --> 10:21.330
So this is another form of decision making statement that you can be able to use in the place of if

10:21.360 --> 10:22.110
statements.

10:22.110 --> 10:25.380
And the if statements can hopefully do the same thing.

10:25.380 --> 10:32.670
But we have to learn every one of them because this is more clear and more concise and more clean and

10:32.670 --> 10:35.640
developing such kind of program.

10:35.640 --> 10:37.350
Now go ahead and practice with that.

10:37.350 --> 10:39.150
Check it out and play around with it.

10:39.180 --> 10:42.720
If you have any questions, go ahead and use the question and answer section.

10:42.720 --> 10:45.390
And I'm going to get back to you as soon as possible.

10:45.390 --> 10:46.380
Thank you so much.

10:46.380 --> 10:49.380
And I'm going to see you in the next video lecture.
