A2 Basic 5 Folder Collection
After playing the video, you can click or select the word to look it up in the dictionary.
Report Subtitle Errors
So let's talk about logical operators.
So we just talked about comparison operators.
So this is where is the value of variable equal to something not equal to something so I don't so forth.
But what if What if the questions a little more wishy washy?
What if What if you need an and or what?
If you need an or right?
What if the value has to be a particular age and something like a gender?
So are you allowed on to, let's say, a woman's only site.
So if you're allowed, if you're gonna be going on to a woman's only site, then it's a woman, so it needs to be equal to or above 18.
And your gender needs to be female, right?
So what?
What if it's something like that?
Or what if it's in?
Or what if it's either the value of a variable is this or the value of a variable is something else.
This is where we come in with logical operators.
This is allows you in an if statement or in a loop, you can say and s.
So if this is true and this is true, or you can say if this is true or this is true, then this code should run.
That's what we're talking about with logical operators.
So with that, let's go over the computer can give you a demonstration on how this works.
So this is a basic script for for logical operators.
Again, we open with a PHP tag.
And for this, we're going to be looking at at pets basically gonna be looking at pets and we're going to be analyzing pets.
So the first thing that we do is we create a variable called dollar signs species.
And currently what we're going to do is we're going to set the value of that variable, too.
Canine double quotation marks and, of course, semi colon.
And we're going to create a variable called $80 sign age, and we're going to set the value of that variable to one against semi colon.
And so then what we're going to do is we're going to come down here, and we haven't if statement and so in the if statement, what we're going to say is if if the species is canine and the age is less than or equal to two, we're going to print It's a puppy, right?
So in order for something to be a puppy, it both has to be a dog and has to be under a certain age at the same time.
So with this, what we're going to say is we're going to say the value of the variable dollar signs species equal to so double equal signs.
And since this is a word so basically a string, we're going to do a single quotation mark and say canine close single quotation marks.
So if the value of a variable is species equals K nine and so for and we do too and symbols back to back.
And then we say the value of the variable age is less than or equal to two, and then we close parentheses.
So this looks like a normal if statement looks like a normal comparison operators.
But we're adding in these list logical operator here to say, and and so it closed that out that we do squiggly brackets and then we all were going to do is going to print It's a puppy and then again, for HTML formatting purposes right here, we're just going to print a break.
And so if the species is canine and the age is less than or equal to two, we're going to print puppy They were going to do another.
If so, we're going to say is this is just a plain if statement no else.
If species equals K nine aye or so, the two, the two upright lines.
So one upper Larry line another upright line.
So if the species equals canine or the species equals cats, then we're going.
What we're going to do is we're going to print your pet is so cute.
So if it's canine and the ages one, the first thing we're going to do is print.
It's a puppy break and then we're on to print.
Your pet is so cute.
So this is how this basically looks, and so with that we can do is you can go up here to the thing D'oh Lodge called up PHP, and so we can see it's a puppy so that that triggers because it's a canine and the ages, too, and then your pet is so cute.
The reason is because it's a canine Now, what if we come here and we change this to cat so now species equals cat eight equals one.
What will happen then?
So hit file save upload the logical.
And now so now there's no longer anything talking about a puppy.
It just says your pet is so cute.
So basically, this is This is how the logical operators work.
What you're looking for is and so if something is true and something else is true, trigger an event or if something is true or something else is true, then trigger something.
And so this is basically all you're looking at with these logical operators.
That's just a brief demonstration of how the logical operators work and Maur less when you're new to Cody and you're going to be using and or or in order to, to see whether something should be triggered, that's that's how you're gonna be doing the comparisons.
But as with everything encoding, there are a lot more options for you.
So if you go over to PHP dot net, you can see that there are more options for logical operators, as I showed you.
Ah, I use the standard way that I learned a code for using and or using or so again either the two uprights for Or or the two the two and symbols for and ah, but np hp.
You can simply type, and if you like, you can type or if you like, or this something's or X o.
If either A or B is true, but not both.
So that's one thing that that that could be a little confusing, especially when you're coding.
So, basically, if A is true and B is false, then it's true.
If a is false and B is true, then it's true.
But if a is true and B is true, then it's false again.
This makes sense when you're doing some higher level coding.
Probably right in the beginning, you don't really need to worry about Zur Ah, and then you also have this guest is simply the exclamation mark point, which is not so.
Basically, this is not true.
So these are some of the different logical operators you could use again in different ways.
You can use the logical operators I would suggest when you're in the beginning, though you use the two basic ways that I showed you.
Once you get more comfortable with using logical operators and start doing more sophisticated things, then you can worry about Zo'or and the rest of this.
So that's all there is, the logical operators really in PHP, and that's that's why it matters.
Basically, all you're doing is you're just tying a lot of different comparisons together and seeing whether you know multiple things are true.
One thing is true.
One thing is false.
So on and so forth again.
This is one of the reasons that I would tell you it's a good idea to pick up a 20 or $30 book because once you start looking at things like comparison operators and the rest of this, if you could just open up a book you have, you have a dog eared and you can look at exactly what you're doing.
It makes life a lot easier again.
This particular book guest has everything listed out here, and so, especially when you're new to Cody and you could just go okay, I need to do this, and I needed to do that and again makes life easy.
    You must  Log in  to get the function.
Tip: Click on the article or the word in the subtitle to get translation quickly!


PHP - Logical Operators

5 Folder Collection
林宜悉 published on March 26, 2020
More Recommended Videos
  1. 1. Search word

    Select word on the caption to look it up in the dictionary!

  2. 2. Repeat single sentence

    Repeat the same sentence to enhance listening ability

  3. 3. Shortcut


  4. 4. Close caption

    Close the English caption

  5. 5. Embed

    Embed the video to your blog

  6. 6. Unfold

    Hide right panel

  1. Listening Quiz

    Listening Quiz!

  1. Click to open your notebook

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔