Req #54739 [NEW]: array_filter: optional parameter for max_items
| From: | ajcoon at gmail dot com | Date: | Sun, 15 May 2011 20:48:35 +0000 |
| Subject: | Req #54739 [NEW]: array_filter: optional parameter for max_items | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-160742@lists.php.net to get a copy of this message | ||
From:
Operating system:
PHP version: 5.3.6
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:array_filter: optional parameter for max_items
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 bug report at http://bugs.php.net/bug.php?id=54739&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54739&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54739&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54739&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=54739&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54739&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=54739&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=54739&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=54739&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=54739&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=54739&r=support
Expected behavior: http://bugs.php.net/fix.php?id=54739&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=54739&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=54739&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=54739&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54739&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54739&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=54739&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=54739&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=54739&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=54739&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=54739&r=mysqlcfg