note 48869 added to function.array-map
| From: | MikeWillbanks at osu1 dot php dot net | Date: | Mon, 10 Jan 2005 03:06:41 +0000 |
| Subject: | note 48869 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83022@lists.php.net to get a copy of this message | ||
bug in the previous submitted array_map_recursive function. simply erase this line: $result +=
$result[$key];
the scope of this bug was if there was multiple arrays the function would place the contents on a
lower level as well as the higher level.
here is the full code:
function array_map_recursive($func, $arr)
{
$result = array();
do
{
$key = key($arr);
if (is_array(current($arr))) {
$result[$key] = array_map_recursive($func, $arr[$key]);
} else {
$result[$key] = $func(current($arr));
}
} while (next($arr)!==false);
return $result;
}
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48869
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48869&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48869&report=yes
Search -- http://master.php.net/manage/user-notes.php