Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46141 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43037 invoked from network); 21 Nov 2009 05:46:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2009 05:46:39 -0000 X-Host-Fingerprint: 92.139.47.76 ANantes-552-1-72-76.w92-139.abo.wanadoo.fr Date: Sat, 21 Nov 2009 00:46:39 -0500 Received: from [92.139.47.76] ([92.139.47.76:11884] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/30-40936-FBE770B4 for ; Sat, 21 Nov 2009 00:46:39 -0500 Message-ID: <1A.30.40936.FBE770B4@pb1.pair.com> To: internals@lists.php.net References: <17.CC.25743.CB6770B4@pb1.pair.com> <200911202328.40520.larry@garfieldtech.com> User-Agent: Pan/0.133 (House of Butterflies) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Posted-By: 92.139.47.76 Subject: Re: [PHP-DEV] suggestion about ternary operator From: seza@paradoxal.org (Alban) Le Fri, 20 Nov 2009 23:28:39 -0600, Larry Garfield a écrit : > 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. Yes, union operator is a pretty solution for arrays. -- Alban Leroux seza@paradoxal.org