Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72342 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83248 invoked from network); 6 Feb 2014 14:38:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2014 14:38:55 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:56850] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 58/33-00209-E7E93F25 for ; Thu, 06 Feb 2014 09:38:54 -0500 Received: by mail-vb0-f42.google.com with SMTP id i3so1502102vbh.29 for ; Thu, 06 Feb 2014 06:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=dS0CQN0cHDKUprQQ4+5jcBAxcXawS7OzqIEgG9Aji2k=; b=NrDcUhq2U+EaMLX8GOdoah4vXW7W1I0FE2MZkPmo3iQgWnK8bArOJMTsqXHzyCXVq/ bfk4lUssohOfvS0ctZEQiUy8sJDgwal7nl7V5Zs9MncEEn8OZLZkGgWuyJdyELXF3CpD 51V0vAKXgLGHCn0ysX+lBoNcJvCTqx8U5KBGs+XHqcVVVYPOXQ5H34vW8vGHHCNpetDH GPKoD9tbyboHHIGTP5U/GcmWULDoVZNe3y24ze4+tDx8I1T/XnERCNjR/twvuojVMVBx P8QvU1uSPrsqZ9rbFXf8Q7FwLk4BgJYaZWULHJq2NZEBNS7BdYJVJBj06zYkbXlcb6d6 5QVQ== MIME-Version: 1.0 X-Received: by 10.52.121.113 with SMTP id lj17mr5116864vdb.21.1391697531229; Thu, 06 Feb 2014 06:38:51 -0800 (PST) Received: by 10.58.133.229 with HTTP; Thu, 6 Feb 2014 06:38:51 -0800 (PST) Date: Thu, 6 Feb 2014 22:38:51 +0800 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=089e0122f1cafbdd9504f1bdd443 Subject: [discussion] add array_usearch() From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e0122f1cafbdd9504f1bdd443 Content-Type: text/plain; charset=ISO-8859-1 Hi internals, To complement array_search(), I'm gauging the interest in adding the following function: mixed array_usearch(array $haystack, callable $fn, int $flags = 0) It returns the first array key from a given haystack for which the callback function returns a truthy value [1] or `false` otherwise. The callback function receives the array item as its only argument [2]. The flags, described below, can be combined by using a binary or. [1] the interpretation of the return value can be inverted by using `ARRAY_USEARCH_INVERT` [2] the array key is passed as the 2nd argument by using `ARRAY_USEARCH_USE_KEY` An implementation of array_all() and array_some(), which you may find in ECMAScript: function array_some(array $array, $fn) { return array_usearch($array, $fn) !== false; } function array_all(array $array, $fn) { return array_usearch($array, $fn, ARRAY_USEARCH_INVERT) === false; } Another example: echo array_usearch(['a', 'b', 2], 'is_numeric'); // 2 The implementation can be found here: https://github.com/datibbaw/php-src/compare/master...array-usearch Let me know your thoughts. -- -- Tjerk --089e0122f1cafbdd9504f1bdd443--