0

Whats up guys LEzStarz here with another PHP tutorial. In this tutorial you will be learning the differences between Comparison Operators, and also you will be learning what type of Operators there are.
What a Comparison operator looks like: "==" or "===".
Okay so lets suppose your aim is to give "x" , "y" an integer value. This is how it would normally look like:
So now just say you want to compare the two variables... How would you do it?PHP Code:<?php
$x = "1";
$y = "1";
or
$x = 1;
$y = 1;
?>
This is how:
By using two equals symbols you are asking > "Are these numbers equal? If yes then tell me they are equal".PHP Code:if($x == $y){
echo "They are equal";
}
Now some people get mixed up with "===" which is also a Comparison Operator but is more specific.
Suppose:
Now you may be thinking this is a valid comparison and the outcome should result to true... Well although it might look like we are comparing the two variables that have the same value's, the outcome will be false.PHP Code:<?php
$x = 1;
$y = "1"; //Not the Quotes.
if($x === $y){
echo "equal";
}
?>
Why?
"===" compares the value's inside the variables BUT also compares the datatype. As you saw:
So the data types here are: Integer which is being compared to and Integer INSIDE a string. This may look complicated but it's very easy to understand after a few example's.PHP Code:$x = 1; //Holds just the integer value.
$y = "1"; //Hold the integer value in the string '""'.
If you want to compare variable's or data and you want to see: If this cake isn't chocolate cake, then tell me it's "It's not chocolate cake".
Here the "!" sign comes in, this can be used on conditions and operators and it basically means, "isn't" that's it.
Example:
This would basically check if the variable $x is not $y then tell me not equal.PHP Code:$x = 1;
$y = "2";
if($x !== $y){
echo "Not Equal";
}
//This is also valid:
if($x !=== $y){
echo "Not equal";
}
Well that's basically Comparison Operators for you, they can be very useful at times when you are using conditions alot, and you want to keep checking something on each page.
Here's a chart to help you understand some more:
If you want to request a tutorial please don't hesitate to, via PM, VM or posting below.
Register or log in to view signatures.
Bugga (07-11-2012), Dan of NGU (07-23-2012), Mr.MoldyOrange (07-20-2012)

Even though I have no idea what I'm looking at...great thread!
Register or log in to view signatures.

Register or log in to view signatures.

Register or log in to view signatures.

Register or log in to view signatures.

Register or log in to view signatures.

Register or log in to view signatures.

I am currently in the middle of learning PHP, this helped out quiet a bit, thanks.
Register or log in to view signatures.