What are Comparison Operators in PHP

in this episode we're going to talk about something called comparison operators inside PHP and this is actually really important episode 4 gas because you will attribute in comparison operators quite often when you write PHP code so as you guys can see it actually write some stuff in the screen already wrote that variable X is equal to five and variable Y is equal to 10 i also wrote something down here which we didn't actually talk about yet called an if-else statement now the basic idea behind an if-else statement is we're going to put something inside these parentheses and if that is true then it's going to do whatever I put down here if whatever is inside the parentheses of Falls then it's going to jump down to the next line and do this down here instead so what we can do is we can actually go and take our variables called x and y put them inside the parentheses and then write something in between them to compare them to each other so that's what we mean by comparison operators whatever we put in between these two variables are going to be the comparison operator so i can actually go ahead and check if these are equal to each other by writing equal equal now you need to understand the difference between writing equal equal equal and equal equal equal because there's actually a difference between them so we write equal was saying that X is equal to five if you write equal equal i can actually write it up here as well then we'll actually checking if x is the same as 5 so there's a difference between using different types of equal signs and this is something that some people might get a little bit confusing in the beginning when you start learning PSP so as long as you learn these differences you should be fine so right now actually checking if x is the same as Y and as we can see it's not so if i go and refresh the browser it should actually say false and as you guys can see if i zoom in a little bit it does actually say false now we can also go ahead and say well ok so these are not equal to each other if I do actually government change my 10 25 now that should actually be equal to each other and say true so if i refresh the browser you can say is true now we can also go in and say okay but what it what if i want to take these are not equal to each other well actually can be using a simple called ! and put in from the equal signs and we're actually going to remove one of the equal signs so we're basically replacing one two equal sides with an exclamation mark which basically says if x is not equal to Y then used to print out true and right now it should actually say false because X is in fact equal to Y they're both five so if i go refresh the browser you guys can say it says faults so if you go back again and change the five back to attend refresh the browser will in fact say true now let's actually go ahead and talk about the next equal sign we put three in here basic what we're saying here is that if X is equal to Y and it's the same data type then shall print out true so if i go ahead and refresh the browser is to promise a false because both x and y are not equal to each other so one will actually both of these conditions actually no one condition is not true right now because they're both the same data type but they're not the same you know number so actually changed my five to attend it will actually say true because now both conditions a true is the same number and the same data type now if we actually go in and change the Y to a string instead of putting you know double quotes around 10 refresh the browser you guys notice it will actually say false and that's because right now the X is a 10 which is an integer and why is a string even though it says 10 if it to actually move 1 equal sign it does not check for data type meaning that these are in fact the same numbers if i refresh the browser it says true even though they're not the same data type now would you also have some other ones and the max you just go ahead and go back a little bit so we have 5 for X and 10 for y so if I go in and delete the equal signs inside the if statement we can actually say if x is less than Y then it's a true by using the less than symbol if i go refresh the browser will say if that's true because X is 5 which is less than 10 if i change this one to greater then it says false now we also have one that says less than or greater than n equal so we can actually say if it's greater than and equal it still says false so right now I can actually set it to let's say we both have 10 4 X + 10 for y so right now it's not greater than X is not greater than Y but it is in fact equal to mean that we will actually get true so we have a bunch of different statements here and there's a lot of them out there well there's not a lot of them out there i think it did actually cover most of them there's one more that we can actually cover actually to we didn't cover yet which is if you want to check if something is not the same number and data type again you just replace one equal sign with an exclamation mark ok so that's the basic difference here another one we can use to check if something is not identical are not equal to each other which would be the same as this right here which we talked about if one of the first ones we can actually go ahead and write less than and equal to or less than and greater than and it will in fact check dese is not equal to each other and it's the same thing so i usually don't use this one because there's another one that does the same one but that's actually the last one we're going to talk about so that's the basic idea behind comparison operators and i'll see you guys next time