|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33447 mixed array_reduce starting value
Submitted: 2005-06-23 11:23 UTC Modified: 2012-07-28 17:32 UTC
From: david dot tulloh at infaze dot com dot au Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5CVS-2005-06-23 (dev) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
23 + 18 = ?
Subscribe to this entry?

 [2005-06-23 11:23 UTC] david dot tulloh at infaze dot com dot au
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");
        create_function('$v, $w', 'return $v.$w;')
    , '')

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-23 12:25 UTC]
And what if you try without the last parameter for array_reduce() ?
 [2005-06-24 02:24 UTC] 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-24 05:10 UTC] david dot tulloh at infaze dot com dot au
Submitted a patch and test file to php-dev.
 [2012-07-28 17:32 UTC]
Closing as this was implemented in 5.3. Demo:
 [2012-07-28 17:32 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 05:04:15 2023 UTC