Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46140 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39595 invoked from network); 21 Nov 2009 05:28:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2009 05:28:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.27.211 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.27.211 qmta11.emeryville.ca.mail.comcast.net Received: from [76.96.27.211] ([76.96.27.211:51812] helo=QMTA11.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/2D-25743-09A770B4 for ; Sat, 21 Nov 2009 00:28:49 -0500 Received: from OMTA19.emeryville.ca.mail.comcast.net ([76.96.30.76]) by QMTA11.emeryville.ca.mail.comcast.net with comcast id 7hNs1d0051eYJf8ABhSRrD; Sat, 21 Nov 2009 05:26:25 +0000 Received: from earth.ufp ([98.220.236.211]) by OMTA19.emeryville.ca.mail.comcast.net with comcast id 7hUl1d0084aLjBW01hUmlx; Sat, 21 Nov 2009 05:28:46 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 7B767D7A3A for ; Fri, 20 Nov 2009 23:28:44 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xA5ic9MIhXKl for ; Fri, 20 Nov 2009 23:28:44 -0600 (CST) Received: from luna.localnet (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id 60A5DD79FE for ; Fri, 20 Nov 2009 23:28:44 -0600 (CST) To: internals@lists.php.net Date: Fri, 20 Nov 2009 23:28:39 -0600 User-Agent: KMail/1.11.2 (Linux/2.6.27-15-generic; KDE/4.2.2; i686; ; ) References: <17.CC.25743.CB6770B4@pb1.pair.com> In-Reply-To: <17.CC.25743.CB6770B4@pb1.pair.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200911202328.40520.larry@garfieldtech.com> Subject: Re: [PHP-DEV] suggestion about ternary operator From: larry@garfieldtech.com (Larry Garfield) On Friday 20 November 2009 11:12:29 pm Alban wrote: > This is not a big problem but if a solution exists, this would be so > cool ! Especialy when we have to check existance of twenty or more key in > array. Code would be be lighter and clear. I cannot comment on the rest of your post right now, but if you are checking for the existence of a bunch of keys in an associative array and setting defaults if they are not set, the following will be considerably faster and easier to read: $my_array += array( 'a' => 'A', 'b' => 'B', 'c' => 'C', ); That will set $my_array['a'] to A iff it doesn't exist, ['b'] to B iff it doesn't exist, etc. That is far nicer to read than a bunch of ternaries, short-circuited or no. You can even stick the defaults array into a function and call it from various places to ensure your array always has the same sane defaults. -- Larry Garfield larry@garfieldtech.com