Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Location
    Earth
    Posts
    144

    Just wondering about the php guy & gals

    Here is my question: In php there is != , ==, || !== , === , what are the differences between them and what and where do you decide to use them?eq
    if($php !== $javascript){
    echo "Good it's not supposed to be";
    }

  2. #2
    Join Date
    Feb 2005
    Location
    Norway
    Posts
    391
    I think some of them are something like this:

    = is is set to
    == is equal to
    != is not set to
    !== is not equal to
    || or
    for example comparing

    $food1="pizza";
    $food2="pizza";
    if($food1 == $food2) {
    echo "yup their equal";
    } else {
    echo "not equal..";
    }

    If thta was what you meant.. hope I made it understandable

  3. #3
    Join Date
    Dec 2000
    Location
    East Coast
    Posts
    1,747
    Comparison Operators
    if ($x != $y) ( ...)
    Returns true if $x is NOT equal to $y, false if equal.

    if ($x == $y) ( ...)
    Returns true if $x is equal to $y, false if it's not equal.

    The above two look at the value of the variable pointers in memory, for ie. if $x is an int and $y is a float, just as long as the value is the same, it neglects any differences in data type.

    if ($x !== $y) ( ...)
    Returns true if $x is is NOT identical to $y, false if equal.

    if ($x === $y) ( ...)
    Returns true if $x is identical to $y, false if it's not equal.

    The above two compares the actual variable pointers to see if they are identical, so $x and $y containing the same value but if those two are different data types, it will be considered as not identical.


    Logical Operators

    The || is a logical operator like &&, ! (bang), and I think the xor too.

    if ($x || $y) ( ...)
    Returns true if either $x and/or $y are true, and false if both are false.

    if ($x && $y) ( ...)
    Returns true if only $x AND $y are true, false if one or both are false.

    if (! $y) ( ...)
    Negates the boolean of $y so returns true only if $y is true, and false if it is true.



    By and by, I'm a bad teacher so hopefully you understand what all that above means.

  4. #4
    Join Date
    Feb 2003
    Location
    Connecticut
    Posts
    5,441
    http://us2.php.net/operators for further reading

  5. #5
    Join Date
    May 2004
    Location
    Singapore
    Posts
    262
    $a == $b returns true if $a and $b are equal, e.g. (1 == '1') is true.
    $a != $b returns true if $a and $b are not equal, e.g. (1 != '1') is false.
    $a === $b returns true if $a and $b are equal and of the same type, e.g. (1 === '1') is false.
    $a !== $b returns true if $a and $b are not equal or are not of the same type, e.g. (1 !== '1') is true.

    Effectively ($a === $b) is a faster shorthand for ($a == $b && gettype($a) == gettype($b)).
    #include<cstdio>
    char*s="#include<cstdio>%cchar*s=%c%s%c;%cint main(){std::printf(s,10,34,s,34,10);}";
    int main(){std::printf(s,10,34,s,34,10);}

  6. #6
    thanks alot this can be useful in future codings i do.

  7. #7
    I learn a lot from your replies, althoughy I'm new in this area. Thanks

Posting Permissions

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