Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62383 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90915 invoked from network); 22 Aug 2012 02:07:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Aug 2012 02:07:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:38459] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/71-10139-5DE34305 for ; Tue, 21 Aug 2012 22:07:18 -0400 Received: by lahl5 with SMTP id l5so279057lah.29 for ; Tue, 21 Aug 2012 19:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=S81OQiTmjjLovAekVvMpTeYGVOXCtqQU7WQHFn8KPNQ=; b=jkcZdddtrjUA2clVvtDWdvzxnW+TMfEofA3kkV0J5xAM/GabES0Vt3hACQ5RBPyoDZ XD2aPIWPN9tnsF7fxFcJmir7o3EHAshOid8LCC0vi9fAIdRigDzAXfjYXW6qlkK7zrLt /I4QkYvhvBaFnbEUo8UdqlrRp4jXjYYug3Dh9W/4A6YzTE/XGygGiiofscN9UaFYRP+q 2W+dd4BBQMvodGlaM3JIHDlHLi2aTndG87GeLi90K90/ryRSm6+BNiaK74Se+HvehG82 bEmpveG+CQhtEbxYla81rKuTzWHYmOP42OW+tRkRzs9e0lJ5EH6w8CsdQqOCFzOe54Iw x7Og== MIME-Version: 1.0 Received: by 10.152.148.199 with SMTP id tu7mr19313097lab.37.1345601235166; Tue, 21 Aug 2012 19:07:15 -0700 (PDT) Received: by 10.112.89.174 with HTTP; Tue, 21 Aug 2012 19:07:14 -0700 (PDT) In-Reply-To: References: Date: Tue, 21 Aug 2012 20:07:14 -0600 Message-ID: To: Yasuo Ohgaki Cc: Rasmus Schultz , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] removing an item from an array From: morrison.levi@gmail.com (Levi Morrison) On Tue, Aug 21, 2012 at 7:45 PM, Yasuo Ohgaki wrote: > > Hi, > > 2012/8/16 Rasmus Schultz : > > How come there is no straight-foward obvious way to simply remove a giv= en > > value from an array? > > > > Just look at the number of horrible ways people solve this obvious prob= lem: > > > > http://stackoverflow.com/questions/7225070/php-array-delete-by-value-no= t-key > > > > Shouldn't we have something simple, like: > > > > array_remove($array, $value) : array (returns a new array) > > > > and/or > > > > array_delete(&$array, $value) : bool (modifies array directly) > > > > ? > > It was amazing that this thread has close to 90 mails. > > I've added some use cases of array_udelete() to wiki, since > some people fails to see how it could be useful. I also bring > back to array_walk() version of equivalent example. I just > don't see any reason why we should replace it with slower > foreach() version. > > I think the RFC page is almost complete. > > https://wiki.php.net/rfc/array_delete > > Any more comments? > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net Take a look at: http://php.net/manual/en/function.array-walk.php#refsect1-function.array-wa= lk-parameters Look at funcname parameter. Notice: > Only the values of the array may potentially be changed; its structure ca= nnot be altered, i.e., the programmer cannot add, unset or reorder elements= . If the callback does not respect this requirement, the behavior of this f= unction is undefined, and unpredictable. I'm just going to change the behavior back when you switch it to array_walk. It's less clear and technically undefined.