need help about php variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wesley1970
    New Member
    • Nov 2007
    • 15

    need help about php variable

    [PHP]<?php
    if ($check!==$_SES SION["validate"]){echo 'Validation is not ok';}
    else { echo 'OK';}
    ?>[/PHP]
    the above doesn't work

    but the below work
    [PHP]<?php
    if ($check==$_SESS ION["validate"]){echo 'ok';}
    else { echo 'validadation is not OK';}
    ?>[/PHP]


    How the variables work logically with 'if' in PHP??? strange

    The below also works

    [PHP]if (strcmp($check, $_SESSION['validation'])==0){echo 'ok';} else {echo 'validation is not OK';}[/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    == means: value is equal: $a == $b Equal TRUE if $a is equal to $b.
    === means: value and data type must be equal: TRUE if $a is equal to $b, and they are of the same type.

    See the php manual on comparison operators

    Ronald

    Comment

    • wesley1970
      New Member
      • Nov 2007
      • 15

      #3
      Thanks very much, actually, not because of it..

      by using strcmp we don't need to trim the string, but i don't know why if i use ==, i have to trim it, by using the below, it works

      [PHP]<?php
      if (trim($check!)! ==trim($_SESSIO N["validate"])){echo 'Validation is not ok';}
      else { echo 'OK';}
      ?>[/PHP]

      Comment

      Working...