Close



Keep me logged in.

Forgot your password? | Register Now

Results 1 to 8 of 8
  1. Original Post
    I'm the illusion
    LEzStarz's Avatar

    Default PHP - Comparison Operators.




    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:
    PHP Code:
    <?php
    $x 
    "1";
    $y "1";
    or 
    $x 1;

    $y 1;
    ?>
    So now just say you want to compare the two variables... How would you do it?
    This is how:
    PHP Code:
    if($x == $y){
    echo 
    "They are equal";

    By using two equals symbols you are asking > "Are these numbers equal? If yes then tell me they are equal".

    Now some people get mixed up with "===" which is also a Comparison Operator but is more specific.
    Suppose:
    PHP Code:
    <?php
    $x 
    1;
    $y "1"//Not the Quotes.

    if($x === $y){
    echo 
    "equal";
    }
    ?>
    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.
    Why?
    "===" compares the value's inside the variables BUT also compares the datatype. As you saw:
    PHP Code:
    $x 1;  //Holds just the integer value.
    $y "1"//Hold the integer value in the string '""'. 
    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.

    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:
    PHP Code:
    $x 1;
    $y "2";

    if(
    $x !== $y){
    echo 
    "Not Equal";
    }

    //This is also valid:

    if($x !=== $y){
    echo 
    "Not equal";

    This would basically check if the variable $x is not $y then tell me 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.

  2. The Following 3 Users Say Thank You to LEzStarz For This Useful Post:

    Bugga (07-11-2012), Dan of NGU (07-23-2012), Mr.MoldyOrange (07-20-2012)

  3. #2
    Previously Zerko
    NextGenUpdate Elite Member
    Bugga's Avatar

    Default


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

  4. #3
    I'm the illusion
    LEzStarz's Avatar

    Default


    0 Not allowed! Not allowed!
    Quote Originally Posted by Zerko View Post
    Even though I have no idea what I'm looking at... great thread!
    Haha thanks, you should learn PHP, it's a great language and very useful.
    Register or log in to view signatures.

  5. #4
    I ♥ Mold

    Default


    0 Not allowed! Not allowed!
    Quote Originally Posted by LEzStarz View Post
    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:
    PHP Code:
    <?php
    $x 
    "1";
    $y "1";
    or 
    $x 1;

    $y 1;
    ?>
    So now just say you want to compare the two variables... How would you do it?
    This is how:
    PHP Code:
    if($x == $y){
    echo 
    "They are equal";

    By using two equals symbols you are asking > "Are these numbers equal? If yes then tell me they are equal".

    Now some people get mixed up with "===" which is also a Comparison Operator but is more specific.
    Suppose:
    PHP Code:
    <?php
    $x 
    1;
    $y "1"//Not the Quotes.

    if($x === $y){
    echo 
    "equal";
    }
    ?>
    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.
    Why?
    "===" compares the value's inside the variables BUT also compares the datatype. As you saw:
    PHP Code:
    $x 1;  //Holds just the integer value.
    $y "1"//Hold the integer value in the string '""'. 
    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.

    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:
    PHP Code:
    $x 1;
    $y "2";

    if(
    $x !== $y){
    echo 
    "Not Equal";
    }

    //This is also valid:

    if($x !=== $y){
    echo 
    "Not equal";

    This would basically check if the variable $x is not $y then tell me 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.
    I learned something today I love you mang
    Register or log in to view signatures.

  6. #5
    I'm the illusion
    LEzStarz's Avatar

    Default


    0 Not allowed! Not allowed!
    Quote Originally Posted by Mr.MoldyOrange View Post
    I learned something today I love you mang
    No problem man!
    Register or log in to view signatures.

  7. #6
    I am the one who knocks
    Elkyeim's Avatar

    Default


    0 Not allowed! Not allowed!
    Quote Originally Posted by LEzStarz View Post
    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:
    PHP Code:
    <?php
    $x 
    "1";
    $y "1";
    or 
    $x 1;

    $y 1;
    ?>
    So now just say you want to compare the two variables... How would you do it?
    This is how:
    PHP Code:
    if($x == $y){
    echo 
    "They are equal";

    By using two equals symbols you are asking > "Are these numbers equal? If yes then tell me they are equal".

    Now some people get mixed up with "===" which is also a Comparison Operator but is more specific.
    Suppose:
    PHP Code:
    <?php
    $x 
    1;
    $y "1"//Not the Quotes.

    if($x === $y){
    echo 
    "equal";
    }
    ?>
    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.
    Why?
    "===" compares the value's inside the variables BUT also compares the datatype. As you saw:
    PHP Code:
    $x 1;  //Holds just the integer value.
    $y "1"//Hold the integer value in the string '""'. 
    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.

    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:
    PHP Code:
    $x 1;
    $y "2";

    if(
    $x !== $y){
    echo 
    "Not Equal";
    }

    //This is also valid:

    if($x !=== $y){
    echo 
    "Not equal";

    This would basically check if the variable $x is not $y then tell me 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.
    Great work Lez! Amazing, well planned out tutorial!
    Keep it up bro. ;D
    Register or log in to view signatures.

  8. #7
    I'm the illusion
    LEzStarz's Avatar

    Default


    0 Not allowed! Not allowed!
    Quote Originally Posted by Elkyeim Psn View Post
    Great work Lez! Amazing, well planned out tutorial!
    Keep it up bro. ;D
    Thanks man :wub: More coming soon!
    Register or log in to view signatures.

  9. #8
    NextGenUpdate Elite
    NextGenUpdate Elite Member
    Dan of NGU's Avatar

    Default


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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •