Re: Control Structure Syntax Question

From: Date: Wed, 10 Mar 2004 04:35:06 +0000
Subject: Re: Control Structure Syntax Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-179979@lists.php.net to get a copy of this message
On 9 Mar 2004 Richard Davey wrote: > $x ? xxx : xxx > > But it makes your code less readable IMHO and offers no tangible > benefit whatsoever. Ah, to each his/her own I guess ... I actually find: $value = ($condition ? $val1 : $val2); easier to read than: if ($condition) $value = $val1; else $value = $val2; On the other hand for this: $value = ($var1 && ($var2 == 4) && (($var3 == $var7) || ($var9 == "hello"))) ? htmlspecialchars(strstr($string1, $string2) . "test") : NULL; I would prefer to use: if ($var1 && ($var2 == 4) && (($var3 == $var7) || ($var9 == "hello"))) $value = htmlspecialchars(strstr($string1, $string2) . "test"); else $value = NULL; In other words ... IMO you can use the ?: operator to be concise (which increases readability) or to be cryptic (which reduces it). -- Tom

« previous php.general (#179979) next »