‫Okay.
‫So now we're going to look at another type of conditional or control structure.
‫And that is a switch.
‫So a switch allows you to test the value of an expression against different cases.
‫And if that value matches a case the code in that case will be executed.
‫If it doesn't match any of the values, then you can have a default case to be executed.
‫And this is a great alternative to an if else if if you if you have a bunch of different conditions
‫because that can get quite messy.
‫So what we're going to do here is something kind of fun.
‫And we have this simple HTML template.
‫And I just have an H1 that says Monday Blues.
‫We have some basic styling where we're setting the background color to blue and using display flex on
‫the body.
‫So everything is in the center.
‫And what I want to do is have a switch where we pass in the day of the week, whatever the current day
‫is, we can use the date function for that, and based on that day, we'll change this message and we'll
‫change the background color.
‫All right.
‫So I have it just it's just obviously just HTML right now.
‫So I have Monday blues and the color blue.
‫So that would be for Monday.
‫But if it's Tuesday then we'll, we'll have a message that says at least it's not Monday.
‫And we'll change the color to green Wednesday.
‫We'll say hump day.
‫So we'll have different messages and colors for whatever day it is.
‫So your result may differ from mine today, Sunday.
‫So mine will say, let's see, what do we have for Sunday?
‫Just have a nice weekend and we'll change the color to yellow.
‫But depending on the day of the week that you're doing this, it'll be different.
‫So let's come up here and let's open up some PHP tags.
‫And to get the day of the week, let's create a variable.
‫We'll just say day of week.
‫And let's set that to date.
‫And we can just pass in a lowercase l.
‫And that will give us the day of the week.
‫In fact, we can test that out by just echoing out.
‫Day of the week.
‫And if I reload you see we get Sunday.
‫Okay.
‫So let's open up a switch statement.
‫So the way that we do this is switch some parentheses, some curly braces.
‫And we put an expression in here to evaluate.
‫And we're just going to pass in the day of the week.
‫And then what we can do from here is create different cases based on what that value is.
‫So we're going to say in the case of it being Monday and then we put a colon here.
‫And whatever we put in here is going to execute if that day of the week is Monday.
‫So what I'm going to do is just set a variable of message, and I'm going to set that to a string of
‫Monday blues.
‫Okay.
‫And then I'm also going to set the color.
‫And I'm going to set the color to blue because I want to change the CSS value to be whatever that color
‫is.
‫Now after you you execute, you put the code you want to execute for that case.
‫Then you just want to add a break at the end of it.
‫All right.
‫And that's pretty much it.
‫So what I'm going to do is grab this and copy it down.
‫Let's we need seven of these for each day of the week.
‫So that's 234567.
‫And then we'll change these up.
‫So this will be Tuesday.
‫And for the message for Tuesday, let's say at least it's not Monday.
‫So at least now in the word, it's I'm going to put in a single quote and I'm wrapping my string in
‫single quotes.
‫So that means I have to escape it with a backslash.
‫So I'm going to say it's not Monday like that.
‫And then for the color we'll set that to green.
‫Then we have Wednesday.
‫And for Wednesday, let's say hump day.
‫Hump day, and we'll set that to orange for the color.
‫Okay.
‫Then we have.
‫The Thursday.
‫And for Thursday, we'll say one more day until Friday.
‫So one more day until Friday and let's make that color.
‫Let's do red for that.
‫Okay, then we have Friday.
‫And for Friday, let's say TGIF.
‫Thank God it's Friday and we'll set that color to purple.
‫And then for for both Saturday and Sunday.
‫So Saturday, both Saturday and Sunday I'm just going to say have a nice weekend.
‫So have.
‫A nice weekend and we'll make the color of that yellow.
‫And I'm going to do the same thing for Sunday, which is today for me.
‫Okay.
‫So I'll save that.
‫And right now, if I reload, we're not going to see any difference because we haven't done anything
‫with these variables.
‫So let's come down here into where we have the CSS.
‫And for the background color, instead of hard coding it as blue, let's just let's just echo out.
‫We can use the shorthand syntax here and let's echo out color like that.
‫So if I reload now you'll see that it's yellow.
‫It's pretty bright.
‫And then down here where we want to put the message, the H one, let's replace this hard code value
‫with.
‫And I'm going to just do string to upper to make it uppercase.
‫And then whatever that message is.
‫So if I reload that, we'll see.
‫We see.
‫Have a nice weekend and you can barely see it.
‫Contrast is kind of off, so let's actually change that to something else.
‫Um what color should we do.
‫We have blue green orange red.
‫Let's do magenta.
‫So we'll do that for Saturday and Sunday.
‫And reload.
‫And there we go.
‫So have a nice weekend.
‫Okay, so that's pretty much it.
‫Pretty simple.
‫You just add in your expression here and you add different cases and then whatever code you want to
‫run for each case.