Req #54739 [Opn->Wfx]: array_filter: optional parameter for max_items
| From: | maarten@php.net | Date: | Thu, 18 Jul 2013 07:54:18 +0000 |
| Subject: | Req #54739 [Opn->Wfx]: array_filter: optional parameter for max_items | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180309@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54739&edit=1
ID: 54739
Updated by: maarten@php.net
Reported by: ajcoon at gmail dot com
Summary: array_filter: optional parameter for max_items
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Arrays related
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
So this is a hint to increase performance. You're probably much better off when filtering much
closer by the logic which gathers the data (i.e. ORDER BY .. LIMIT).
Also, some sort of slipper slope, one might argue a (sometimes micro) optimization when adding this
parameter to a lot of array functions, and I don't think it all added parameters, documentation
and edge cases are worth it.
Previous Comments:
------------------------------------------------------------------------
[2011-05-15 22:48:34] ajcoon at gmail dot com
Description:
------------
Per this discussion on StackOverflow, I would like to recommend an additional, optional parameter be
supported in
array_filter. The parameter, named max_items (or similar)
would be expected as an integer value >0, and used to return a max of n matching
items in the search array. This is useful in the case where sort order is non-deterministic and the
number of desired items is low relative to the length of the search array.
Related discussion:
http://stackoverflow.com/questions/6010872/getting-a-value-from-an-array-in-php
Test script:
---------------
$objects = array_filter($myArray, function($item){ return $item->id == 91 }, 1);
Expected result:
----------------
Expect array_filter to stop searching for additional matches once it reaches
max_items number of matches.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54739&edit=1