RE: [PHP] question about ? :

From: Date: Fri, 14 Jun 2002 00:22:19 +0000
Subject: RE: [PHP] question about ? :
Groups: php.general 
Request: Send a blank email to php-general+get-102113@lists.php.net to get a copy of this message
Lee - I would bracket anyway, just to make sure, and to make it clear to the coder what's happening Miguel - that's fine when using two operators that have different precedence, but all three operators are ?: -----Original Message----- From: Miguel Cruz [mailto:mnc@stoic.net] Sent: Friday, June 14, 2002 10:13 AM To: Lee Doolan Cc: php-general@lists.php.net Subject: Re: [PHP] question about ? : On 13 Jun 2002, Lee Doolan wrote: > the arrays below have dates like > dateA= array( 0=> "03", 1=> "22", 2=> "02") > > for 22march2002. > > 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; Why does this: $x = 3 + 5 * 7; produce different results from this: $x = (3 + 5) * 7; ? miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#102113) next »