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

 ID:                 33447
 Updated by:         [email protected]
 Reported by:        david dot tulloh at infaze dot com dot au
 Summary:            mixed array_reduce starting value
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 PHP Version:        5CVS-2005-06-23 (dev)
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

Closing as this was implemented in 5.3. Demo: http://viperpad.com/bMpmeO


Previous Comments:
------------------------------------------------------------------------
[2005-06-24 05:10:32] david dot tulloh at infaze dot com dot au

Submitted a patch and test file to php-dev.

------------------------------------------------------------------------
[2005-06-24 02:24:42] david dot tulloh at infaze dot com dot au

The solution you provided does work for my example.  However, I still think it 
would be a good feature to have.

The actual initial purpose I had in mind was to flatten arrays.

$list = Array( Array("a"), Array("b"), Array("c") );
$flat = array_reduce($list, 'array_merge');

Which will unfortunately fail.


Only allowing an integer or null starting type is an odd limitation, 
particularily as the array can contain any type.

------------------------------------------------------------------------
[2005-06-23 12:25:44] [email protected]

And what if you try without the last parameter for array_reduce() ?

------------------------------------------------------------------------
[2005-06-23 11:23:28] david dot tulloh at infaze dot com dot au

Description:
------------
The array_reduce function currently only starts with an integer value.  This 
seriously limits it's functionality.

For example, it should be trivial to use array_reduce to concatonate an array 
of strings.  This currently isn't possible.

Reproduce code:
---------------
$list = Array("page1", "page2", "page3");
print_r(
    array_reduce($list,
        create_function('$v, $w', 'return $v.$w;')
    , '')
);


Expected result:
----------------
page1page2page3

Actual result:
--------------
0page1page2page3


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



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

Reply via email to