Req #60908 [Opn]: Please add array_filter_recursive function

From: Date: Fri, 08 May 2015 22:19:39 +0000
Subject: Req #60908 [Opn]: Please add array_filter_recursive function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192597@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60908&edit=1

 ID:                 60908
 Updated by:         cmb@php.net
 Reported by:        benjamwelker at gmail dot com
 Summary:            Please add array_filter_recursive function
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   Win 7 64
 PHP Version:        5.3.9
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-01-27 18:04:18] benjamwelker at gmail dot com

Description:
------------
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.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=60908&edit=1


Thread (3 messages)

« previous php.bugs (#192597) next »