From:             
Operating system: All
PHP version:      5.3.5
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:Feature request - function array_walk_recursive

Description:
------------
---

>From manual page:
http://www.php.net/function.array-walk-recursive#Parameters

---



This function does not send arrays to the callback function, and in most
cases this is what you want, but sometimes you may need at least the keys
of the arrays (example below). My suggestion is to add a fourth parameter
to this function which takes a boolean value, and defaults to FALSE. The
callback function can then handle the arrays and their keys if this
parameter is set to TRUE.



One usage for this feature would be if you want to make a custom function
for serializing an array and all its content. A serialized string must
contain the keys of child arrays, else the custom unserializer will be
unable to restore child arrays properly. A custom serializer may be able to
make binary strings rather than human-readable strings like serialize()
does, which will save a lot of space e.g. when storing $_SESSION data in a
database.



Additionally, this feature would also allow custom output of arrays in a
human-friendly way, especially if the callback function can get the depth
of the iteration (see the code example below).

Test script:
---------------
function awr_callback(&$val, &$key, &$ptr, $depth = 0) {

 $indent = str_pad('', $depth, ' ');

 if (is_array($val)) $ptr[0] .= "${indent}Array '$key' (" . count($val) .
"):\n";

 elseif (is_string($val)) $ptr[0] .= "${indent}String '$key' (" .
strlen($val) . "): $val\n";

 // ...

}



$a = array('beginning', 'first child' => array('an element', 'another
element'), 'end');

$s = '';

array_walk_recursive($a, 'awr_callback', array(&$s), true);

echo $s;



// This short example is written to demonstrate usage of the suggested
features, and will not work with the current version of PHP.

Expected result:
----------------
Expected output when/if the features are implemented:



String '0' (9): beginning

Array 'first child' (2):

 String '0' (10): an element

 String '1' (15): another element

String '1' (3): end

Actual result:
--------------
Actual output (if you first remove the fourth input parameter when calling
array_walk_recursive):



String '0' (9): beginning

String '0' (10): an element

String '1' (15): another element

String '1' (3): end

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54076&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54076&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54076&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54076&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54076&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54076&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54076&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54076&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54076&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54076&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54076&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54076&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54076&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54076&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54076&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54076&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54076&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54076&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54076&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54076&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54076&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54076&r=mysqlcfg

Reply via email to