Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62202 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98435 invoked from network); 15 Aug 2012 20:22:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2012 20:22:24 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.123 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.123 smtp123.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.123] ([67.192.241.123:36761] helo=smtp123.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/84-08779-EF40C205 for ; Wed, 15 Aug 2012 16:22:23 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 356657823F; Wed, 15 Aug 2012 16:22:20 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp2.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id DA42D781BB; Wed, 15 Aug 2012 16:22:19 -0400 (EDT) Message-ID: <502C04FB.2010000@sugarcrm.com> Date: Wed, 15 Aug 2012 13:22:19 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Rasmus Schultz CC: "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] removing an item from an array From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > How come there is no straight-foward obvious way to simply remove a given > value from an array? The same reason there's no simple way to undefine variable whose value is 42 without knowing the variable name. Array is a container indexed by keys, not values. So if you've got just a value, there's no way to know if it's in the container at all, and if it is, where it is, except for going through all the values and checking if any of them is equal to what you nedd. > Just look at the number of horrible ways people solve this obvious problem: I see: if(($key = array_search($del_val, $messages)) !== false) { unset($messages[$key]); } Nothing horrible here. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227