|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-06-23 11:23 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
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.