Question about PHP comparison operators

Discussion in 'PHP' started by ketting00, Oct 14, 2010.

  1. #1
    Hi All!

    I'm amateur PHP coder and is wondering about these comparison operators.
    Mostly I use

    x == y, x != y, x < y , x > y, x <= y, and x >= y.

    But sometimes I see a nerd use these operators: x => y, and x -> y.

    So when should I use these. Is there tutorial about this. I've done some research but yield nothing.

    Thanks in advance.
     
    ketting00, Oct 14, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You can find everything you need to know on the PHP site!

    A quick search and you can find them all here;

    http://php.net/manual/en/language.operators.php

    If there is a specific operator that is causing you grief, let me know
     
    lukeg32, Oct 14, 2010 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #3
    Thanks for response. I'll learn how to use them.

    Edited: It's look like I'm going to get an headache with this tutiorial. D:
     
    ketting00, Oct 14, 2010 IP
  4. magiatar

    magiatar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    This 2 are not comparison operators:

    x => y, and x -> y.

    In some languages, not PHP, x=>y is the same as y<=x.
    In PHP, => is not a comparisson, so avoid using it !!!

    => is used in arrays definitions (see arrays on the php help)


    $arr = array("foo" => "bar", 12 => true);

    echo $arr["foo"]; // bar
    echo $arr[12]; // 1



    -> is not a comparison operator !!!
    Usually, on C++, it's used as a "pointer reference", to use a property/method of an object.
    In PHP, you can use the DOT (.)

    So, please, don't use => nor -> as comparison operators, because they are not.
     
    Last edited: Oct 15, 2010
    magiatar, Oct 15, 2010 IP