|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60908 Please add array_filter_recursive function
Submitted: 2012-01-27 18:04 UTC Modified: 2021-02-01 14:37 UTC
Avg. Score:2.2 ± 0.8
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: benjamwelker at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Arrays related
PHP Version: 5.3.9 OS: Win 7 64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: benjamwelker at gmail dot com
New email:
PHP Version: OS:


 [2012-01-27 18:04 UTC] benjamwelker at gmail dot com
A function like
array array_filter_recursive ( array $array [, callback $callback] )
would be very useful.

I'm not sure how it would react when encountering empty arrays within the given 
array, though.  The expected result would probably be to keep the empty arrays.

Although removing them would be desired under certain conditions as well.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-08 22:19 UTC]
In my opinion, adding more array_*_recursive() functions should be
avoided. Instead it might be useful to have array_flatten(), so
one could do

  array_filter(array_flatten($array), $callback)
Then again, defining array_flatten() in userland is quite simple:

  function array_flatten($array) {
      return array_reduce($array, 'array_merge', []);

Anyhow, with regard to the mentioned issue of empty arrays, it
seems indeed best to leave the implementation for userland.
 [2021-02-01 14:37 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-02-01 14:37 UTC]
According to my comment above, I'm closing this ticket. If anybody
still thinks it would be a useful addition to the standard
library, please pursue the RFC process[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 08:01:29 2024 UTC