|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-10 10:24 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
Description: ------------ array_map fails to work recursively. It does not pass by reference in the inner array_map call. Changing the line to $ret = array_map('ref_map', &$item); provides the expected result but throws a Call-time pass-by-reference warning. Reproduce code: --------------- <?php function ref_map(&$item) { if(!is_array($item)) { $item = 1; return 2; } else { $ret = array_map('ref_map', $item); echo 'Inner return: '; print_r($ret); echo 'Inner item: '; print_r($item); return $ret; } } $a = array(array(0), 0); $ret = array_map('ref_map', $a); echo 'Array: '; print_r($a); echo 'Return: '; print_r($ret); ?> Expected result: ---------------- Inner return: Array ( [0] => 2 ) Inner item: Array ( [0] => 1 ) Array: Array ( [0] => Array ( [0] => 1 ) [1] => 1 ) Return: Array ( [0] => Array ( [0] => 2 ) [1] => 2 ) Actual result: -------------- Inner return: Array ( [0] => 2 ) Inner item: Array ( [0] => 0 ) Array: Array ( [0] => Array ( [0] => 0 ) [1] => 1 ) Return: Array ( [0] => Array ( [0] => 2 ) [1] => 2 )