RE: question about ? :

From: Date: Wed, 19 Jun 2002 19:21:10 +0000
Subject: RE: question about ? :
Groups: php.general 
Request: Send a blank email to php-general+get-102995@lists.php.net to get a copy of this message
Well, I knew one day my tendency to oversnip messages would cause havoc, and today's it! All of you very kindly pointed out exactly why the two expressions are different, some of you at great length -- but the question was directed back to the original poser of the ?: question (Lee Doolan, I think) as an example to illustrate why parentheses might make a world of difference to apparently similar expressions. As such, I was intending it as an "exercise for the reader", and not expecting so many long and thoughtful answers. So, just to recap, Lee's original question was: > why does this work: > > $retval= ($dateA[2] != $dateB[2]) > ? strcmp($dateA[2], $dateB[2]) > : (($dateA[0] != $dateB[0]) > ? strcmp($dateA[0], $dateB[0]) > : (($dateA[1] != $dateB[1]) > ? strcmp($dateA[1], $dateB[1]) > : 0)); > > > but not this: > > $retval= ($dateA[2] != $dateB[2]) > ? strcmp($dateA[2], $dateB[2]) > : ($dateA[0] != $dateB[0]) > ? strcmp($dateA[0], $dateB[0]) > : ($dateA[1] != $dateB[1]) > ? strcmp($dateA[1], $dateB[1]) > : 0; and my (ultimate) response was: > > Why does: > > > > $x = 9 - 5 + 3; // 7 > > > > produce a different result from: > > > > $x = 9 - (5 + 3); // 1 So, can we put a cap on this thread, now, please? 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

« previous php.general (#102995) next »