Help me with this boolean logic

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Audleman

    #1

    Help me with this boolean logic

    I wrote a piece of boolean logic that doesn't work and I don't know
    why. The code should ONLY do something if the session variable is
    equal to 900123:

    if( ! $_SESSION['SubscriptionID '] == '900123') {
    //do some logic
    }

    However it always returns true. After staring at it for a while, I
    realized that the PHP way of doing things is to use the != operator,
    instead of putting ! at the front of the entire statement (I've been
    doing too much Filemaker scripting). However I can't figure out why
    this code shouldn't work. Does anybody have some insight?

    Cheers,
    Kevin
  • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

    #2
    Re: Help me with this boolean logic

    *** Kevin Audleman escribió/wrote (Wed, 13 Aug 2008 08:44:09 -0700 (PDT)):
    I wrote a piece of boolean logic that doesn't work and I don't know
    why. The code should ONLY do something if the session variable is
    equal to 900123:
    >
    if( ! $_SESSION['SubscriptionID '] == '900123') {
    //do some logic
    }
    Read the section about operators precedence in the PHP manual:



    Your code equals to:

    (!$_SESSION['SubscriptionID ']) == '900123'



    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor en cubitos: http://www.demogracia.com
    --

    Comment

    • Kevin Audleman

      #3
      Re: Help me with this boolean logic

      Read the section about operators precedence in the PHP manual:
      >
      http://es.php.net/manual/en/language...uage.operators...
      >
      Your code equals to:
      >
      (!$_SESSION['SubscriptionID ']) == '900123'
      >
      --
      --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
      -- Mi sitio sobre programación web:http://bits.demogracia.com
      -- Mi web de humor en cubitos:http://www.demogracia.com
      --
      Thank you Alvaro!

      Kevin

      Comment

      • Michael Fesser

        #4
        Re: Help me with this boolean logic

        ..oO(Kevin Audleman)
        >I wrote a piece of boolean logic that doesn't work and I don't know
        >why. The code should ONLY do something if the session variable is
        >equal to 900123:
        >
        >if( ! $_SESSION['SubscriptionID '] == '900123') {
        //do some logic
        >}
        In addition to the other answer: Why is the number quoted? Is the ID
        numeric or a string?

        Micha

        Comment

        Working...