Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62203 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99740 invoked from network); 15 Aug 2012 20:24:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2012 20:24:03 -0000 Authentication-Results: pb1.pair.com header.from=wfitch@meetme.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=wfitch@meetme.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain meetme.com designates 74.125.149.151 as permitted sender) X-PHP-List-Original-Sender: wfitch@meetme.com X-Host-Fingerprint: 74.125.149.151 na3sys009aog124.obsmtp.com Linux 2.5 (sometimes 2.4) (4) Received: from [74.125.149.151] ([74.125.149.151:55777] helo=na3sys009aog124.obsmtp.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E7/D4-08779-1650C205 for ; Wed, 15 Aug 2012 16:24:02 -0400 Received: from mail-ob0-f181.google.com ([209.85.214.181]) (using TLSv1) by na3sys009aob124.postini.com ([74.125.148.12]) with SMTP ID DSNKUCwFXncITTDv5QLOh4M7+mSPpXJkCRdM@postini.com; Wed, 15 Aug 2012 13:24:02 PDT Received: by obbup19 with SMTP id up19so2816208obb.26 for ; Wed, 15 Aug 2012 13:23:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=Db1VYCh//OekSmgWgLWURq4+nVzR7WpKf6V767zsn9U=; b=VqwZ8ervBw33oDltHEpYjLTPbSZ6jtv5XZi3wY9tG1cS+Xfq4jVOuAvXOkk69tAINo 7tVOYpCh+OzoAt1rZ7usc5sS7G64Fla00PmzbhMDcx+6Epopv/Ni/31ikaqA515bgwRK KgOIBcxjrilLdyPiH3xh8AZeBGHAJF8h2D9xLwgk2SOsbyNUaeSUx0WEb5cdnfjrNEJt CwfnDCuXwCfu4meMWydfwBgVIKLuHZhUKG61ex9XBFb20ogbei4vx75q3sLnQprIBtnm Twd8IgcBcx0tRoAqvGXuWWlhGfkBMGn3UZ/Hx3w/LhWTKVfRWNrrlYQfAd+cHKVDud+4 XReg== MIME-Version: 1.0 Received: by 10.182.218.37 with SMTP id pd5mr25244356obc.24.1345062237454; Wed, 15 Aug 2012 13:23:57 -0700 (PDT) Sender: wfitch@meetme.com Received: by 10.60.142.138 with HTTP; Wed, 15 Aug 2012 13:23:57 -0700 (PDT) X-Originating-IP: [204.145.120.11] In-Reply-To: <502C04FB.2010000@sugarcrm.com> References: <502C04FB.2010000@sugarcrm.com> Date: Wed, 15 Aug 2012 16:23:57 -0400 X-Google-Sender-Auth: cgG878vMtCA3XZzlK_OAhd_jHns Message-ID: To: Stas Malyshev Cc: Rasmus Schultz , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d04447dffdd3f8204c753b41a X-Gm-Message-State: ALoCoQluVVcyQmOzHZONVIWC4s2xMsfP/IvSUkoSiWQ8W6+qUByL8tLsFxAasv44+awLl6ZikQLq Subject: Re: [PHP-DEV] removing an item from an array From: willfitch@php.net (Will Fitch) --f46d04447dffdd3f8204c753b41a Content-Type: text/plain; charset=ISO-8859-1 I like that chose 42 for the value. You win, and I completely agree. On Wed, Aug 15, 2012 at 4:22 PM, Stas Malyshev wrote: > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d04447dffdd3f8204c753b41a--