By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Help me with this boolean logic

P: n/a
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
Aug 13 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
*** 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:

http://es.php.net/manual/en/language...ors.precedence

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
--
Aug 13 '08 #2

P: n/a
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
Aug 13 '08 #3

P: n/a
..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
Aug 13 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.