php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63148 Pass array key to array_filter function callback
Submitted: 2012-09-24 09:18 UTC Modified: 2015-08-27 21:49 UTC
Votes:2
Avg. Score:1.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hradtke@php.net Assigned: nikic (profile)
Status: Closed Package: Arrays related
PHP Version: 5.4Git-2012-09-24 (Git) OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hradtke@php.net
New email:
PHP Version: OS:

 

 [2012-09-24 09:18 UTC] hradtke@php.net
Description:
------------
I would like to change array_filter to following prototype:

proto array array_filter(array input [, mixed callback, bool pass_key])

The callback prototype would change to:
proto bool callback(mixed value [, mixed key])


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-25 02:49 UTC] laruence@php.net
Hey, we have various array functions, and I do believe this can be done in another 
ways, 

so, why introduce this? thanks
 [2012-09-25 03:07 UTC] hradtke@php.net
Everything that array_filter does can be done with a foreach loop though. Some 
people prefer the functional approach instead though.
 [2012-09-25 03:48 UTC] hradtke@php.net
Also, the other functions, such as http://php.net/array_map, provide the key.
 [2012-09-25 09:52 UTC] laruence@php.net
the problem is not about consistent with other functions, the problem is do we 
really need this?

maybe you should write to internal ML, get some more disscussion? :)

thanks
 [2015-08-27 21:49 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-08-27 21:49 UTC] nikic@php.net
Supported since 5.6 via the ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH flags.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 02 13:01:31 2025 UTC