Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62360 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46215 invoked from network); 21 Aug 2012 21:19:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2012 21:19:38 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:51247] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/97-10139-86BF3305 for ; Tue, 21 Aug 2012 17:19:37 -0400 Received: by weyr1 with SMTP id r1so190403wey.29 for ; Tue, 21 Aug 2012 14:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=jlHApTXzyROzO/g5sTHyP4MlfNf6dKb8PV7dUEbbhCw=; b=GHIIr3p7jv3e9R0YnRKdxeK7QyFYpPT9NUyEhwD84QslOKWyiqlD2U7RMLNiADgy88 yjNegIBSLoV2nvSNqseCS87k6WY4ozDFuoivz20FAi9iljyWY0xvcfb44X8yRbtoX/qm uQcUxWHmfc7NcjN3p3dyQ+OGgHQKhB146oe86E0foTGOKA+0CDhHK5OCjZhzABC7lDgv ZpMM12tLIm0haIq7wKTSIN9NWh3B3F1U9IC1No+DYWsOtvJc6kZJ9O0bb4MuSw3CPpu7 oJS1DJNReunVmL414i4NCFTj2vk4HD2L6wLK/BY/cLqDoOzkmP3Y+0+eEk7k1nropYYk U0zg== Received: by 10.216.195.40 with SMTP id o40mr10159861wen.36.1345583973402; Tue, 21 Aug 2012 14:19:33 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.223.86.201 with HTTP; Tue, 21 Aug 2012 14:18:53 -0700 (PDT) In-Reply-To: <5033F1EA.4070701@ajf.me> References: <5033E0BC.8040507@ajf.me> <5033EAAB.6090502@ajf.me> <5033F1EA.4070701@ajf.me> Date: Wed, 22 Aug 2012 06:18:53 +0900 X-Google-Sender-Auth: 11YLXwcBUMTbYMKgKe6vaYdFhYM Message-ID: To: Andrew Faulds Cc: Tjerk Anne Meesters , Rasmus Schultz , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] re: removing an item from an array From: yohgaki@ohgaki.net (Yasuo Ohgaki) 2012/8/22 Andrew Faulds : > Er, so you're advocating adding another method to do the same thing? Why? Because novices don't know about array_walk(). I think I've written this over and over in this thread. > The whole point of this was to allow people to use arrays like sets, or > easily remove list items. Not encourage people to use functional > programming. > > Sure, people should use array_walk, but you've got to be kidding me if I you > think I would honestly accept using this to remove array items by value: > > array_delete($array, function ($value) { return ($value == "that value"); > }); > > I might as well use array_walk if we're going down this route. You seem to > want to subvert the usefulness of this function and just provide an > array_walk shorthand with less functionality. > > What I want is this: > > array_delete($array, "that value"); I do not want this ;) What's wrong with extensible way? It's for PHP 5.5, not PHP 4. array_delete($array, function ($v) { return ($v == "that value"); }); We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. We may pass them as parameter, array_delete($array, "that value", "!=="); but it does not look a modern way to do and it is not extensible like with callable. Besides, how often we would like to delete elements based on element's value? I guess it's not so often for most people. > Much more readable, does what you expect, and provides a significant, > noticeable value over array_walk here. array_walk() is easy to use, IMHO. People just don't know array_walk() can be used to delete elements because of it's name. As I wrote in sample code, new array_delete is an intuitive name and convenient than array_walk. They are like array_pop/array_push and array_slice/array_splice to me. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net > >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohgaki@ohgaki.net >> >> >>>> As I mentioned earlier, array_walk() is the best way to delete elements >>>> with PHP >>>> more than a decade. It should be mentioned the Stack Overflow page, >>>> but it's not. >>>> >>>> It's just like adding >>>> array_pop()/array_push()/array_shift()/array_unshift() while >>>> we have array_slice()/array_splice(). >>>> >>>> Regards, >>>> >>>> -- >>>> Yasuo Ohgaki >>>> yohgaki@ohgaki.net >>> >>> >>> >>> -- >>> Andrew Faulds >>> http://ajf.me/ >>> > > > -- > Andrew Faulds > http://ajf.me/ >