note 48869 deleted from function.array-map by didou
| From: | didou@php.net | Date: | Mon, 10 Jan 2005 03:18:01 +0000 |
| Subject: | note 48869 deleted from function.array-map by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83025@lists.php.net to get a copy of this message | ||
Note Submitter: Mike Willbanks
----
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;
}