RE: [PHP] RE: question about ? :

From: Date: Wed, 19 Jun 2002 13:55:38 +0000
Subject: RE: [PHP] RE: question about ? :
Groups: php.general 
Request: Send a blank email to php-general+get-102932@lists.php.net to get a copy of this message
>>Why does: >> >> $x = 9 - 5 + 3; // 7 it works out: 9 - 5 = 4 then 4 + 3 = 7 >> >>produce a different result from: >> >> $x = 9 - (5 + 3); // 1 this time it works out: 5+3 = 8 it does this first, and then the subtraction: 9 - 8 = 1 > -----Original Message----- > From: Ford, Mike [LSS] [mailto:M.Ford@lmu.ac.uk] > Sent: 19 June 2002 2:34 PM > To: 'Joel Boonstra'; Ford, Mike [LSS] > Cc: 'Lee Doolan'; php-general@lists.php.net > Subject: [PHP] RE: question about ? : > > > > -----Original Message----- > > From: Joel Boonstra [mailto:jboonstra@gospelcom.net] > > Sent: 19 June 2002 14:00 > > > > > OK, try this: why does > > > > > > $x = 3 + 5 - 7; > > > > > > produce different results from > > > > > > $x = 3 + (5 - 7); > > > > Really? It shouldn't produce different results for you -- > they should > > both evaluate to '1'. > > Jeez, you're right! That was dumb!! Somehow I suffered a > brain-wibble that > managed to calculate 5-7 as +2 rather than -2. As I studied > maths all the > way up to 1st year at university -- and do understand the rules of > precedence and associativity, honest, boss -- I really > shouldn't have made > that kind of basic error. > > Still, the principle I was trying to illustrate is still > good, even if my > example was complete codswallop, so let's try again. > > Why does: > > $x = 9 - 5 + 3; // 7 > > produce a different result from: > > $x = 9 - (5 + 3); // 1 > > Cheers! > > Mike > > --------------------------------------------------------------------- > Mike Ford, Electronic Information Services Adviser, > Learning Support Services, Learning & Information Services, > JG125, James Graham Building, Leeds Metropolitan University, > Beckett Park, LEEDS, LS6 3QS, United Kingdom > Email: m.ford@lmu.ac.uk > Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#102932) next »