I will call you back again to add a video lecture in PHP.
And in this video lecture we go ahead and look at switch statement in PHP.
So switch statement is another type of decision making statement in PHP that is used to compare one
value with bunch of other values in your program.
So you can have so many switch cases.
And in some statements it uses these two keywords switch and cases.
We add a switch.
We actually do the job of uh showing you the, the variable.
And then the case.
We actually give you the values which are going to compare.
So you have the switch.
Then you have so many cases to compare.
So once you set the variable inside the switch, then you go ahead and begin to compare different different
cases.
So you won't have case one, case two three, four to as many possible cases as you want.
Now let me go ahead and use maybe the football.
Maybe if we insert remove and it's going to say uh escort that goes under or let's go ahead and use
something very simple and very, uh, unique like the students grid.
So first of all, I'll create a form for this.
We want to say form.
And then we go ahead and close this.
And then let's go ahead and uh, put in action.
And that is going to be site that PHP.
And then we'll go ahead and say mytouch and let the method be post method.
And then we go ahead and create a form.
And let the form we create is going to be a form that's going to ask students for their grid to understand.
what I'm going to say?
In such great.
So.
In such great.
And then go ahead and put the grid so inputs and the, the type of the input is going to be just text.
So and let the method which are going to use here is okay I might say method let name.
So let name be equal to grid.
All right.
So go ahead and close this.
And let's go ahead and impute our submit button.
So input type and the input type be submit.
All right.
So I'm trying to write submit.
Now go ahead and close this.
And if we go on go ahead and refresh this.
We have our inset grid.
And then go ahead and submit that.
So I hope that is good.
So let's go ahead and just put in Greek.
I just want this to be short.
So go ahead and save.
Great.
And save this and refresh.
We have great input.
Great.
We go ahead and submit that.
Now if I try to go right in here and create move ahead and create a.
A variable and let variable be equal to.
Let me see if we go ahead and see posts.
And then we go ahead and say grid because I think in the grid right in here, go ahead and place semicolon
at the end.
And then we go ahead and execute this.
So we go ahead and echo whatever the user puts in there.
So with semicolon at the end and let's save this.
Now go ahead and refresh this.
And uh this arrow always cool.
Now if you want this error to stall, this is not an error from your computer.
If I go ahead, I click a submit.
This error will actually go out.
You see that if I click on this it goes out.
What if you don't want to do that.
You go ahead and put PHP error or put in.
You understand and let the error button be equal to zero and it will no longer do that.
So let me go ahead and say we have a A and if you submit it's going to print out A.
If you have B it's going to print out B, if you have C it's going to print out C.
Now what to tell you, the user whenever you insert A is going to see you have an A or you have an A
grade.
So how can we be able to do that.
Because these this code and one can not be able to do that for us.
So in order to do that I'm going to remove whatever we have right in here.
And let's go ahead and write a switch statement.
So First of all, I'll go back to paste this.
I'll go ahead and remove the echo.
Then I'm going to put the echo right inside the switch statement I'm going to create.
So go ahead and say switch.
And you see when I click on switch the first one I have is the variable which is this variable here.
Like I told you the variable is the first thing you insert into the switch.
So great.
Now it has created some cases for you.
And then the default.
The default is the last of all days.
So if all the cases are not met then it goes on to print out the default.
So if it fails to get anything from the value from the cases, then it will actually print out the default.
You understand.
Now let's go ahead and see case which is how this case holds the value.
So let me say this is an A you understand.
And it goes on to echo out the migraine and say Echo.
And it's good to see you.
Have you have an.
Excellent grade.
All right.
So anyone that has an A we always have an excellent grade.
Now I'll go ahead and copy this.
So now what it break does is that if it checks a it will actually break out from A and then check B.
And in that way it will check all of them.
Let's go ahead and paste that.
So can you to understand explain that better.
So I inserted another one.
And uh so let's go ahead and insert this one then the next one.
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.
The B is going to be you have an amazing grade.
The C is going to be you have a good grade then the D is going to be you have a Fe Great Dane.
The E is going to be you have.
Let me say you have a bad grade.
All right.
So the last one is going to be your failed.
So.
You've heard.
So now if it checks all these grades and it didn't get anything.
Now what happens is that it goes to default and it's going to echo, as I say, echo invalid.
Great.
Now let me go ahead and explain all this.
Let me go ahead and explain what we just did right in here.
Now for the switch cases it checks on.
We create a switch and we pass in the variable grid, which gets whatever inputs the user in certain
right inside this, uh, form.
So and then the name is grid and that is what we inserted inside.
Or we save inside this variable called grid.
And now we begin to check the input.
So if a user inserts E we're going to echo out.
You have an excellent grid.
And if we check and the user didn't insert a we break out of this case.
So you can see I added breaks in every one of the cases.
So whenever it checks a case and the case didn't meet up or it will not remain there, it will break
out and move to the next one.
So when it checks all of these cases and it did not meet any one, it goes on and say invalid grid.
Now let's go ahead and save this.
I'm going to refresh this guy on a fresh.
You have an excellent grid because I inserted an A.
So if I put in F and submit invalid because here I select the A right in here.
So I've changed that to F.
And now I will replace this.
And the default.
You see that.
So if I insert e and submit you have a bad grid.
You if you insert a D it says you have, oh this should be a fake grid and not a.
All right.
So I didn't change all these things shall be good amazing and excellent and so on.
Let's go ahead and check it out.
Now let's go ahead and add Z and submit invalid grade, so the grade ranges from A to F, and anything
apart from D is an invalid grade, so you can actually use the if else if statement to do this.
But you can see that this is more shorter, more simple and uh, more clear to developers than the if
else statement.
So this is another form of decision making statement that you can be able to use in the place of if
statements.
And the if statements can hopefully do the same thing.
But we have to learn every one of them because this is more clear and more concise and more clean and
developing such kind of program.
Now go ahead and practice with that.
Check it out and play around with it.
If you have any questions, go ahead and use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.