It is necessary to replace the array values ​​with others, the array can be any nesting. Can I do this by reference using recursion? The code is simply an example, the purpose of which is to change 'three' to 'five' using recursion.

$a=['one'=>['two'=>'three']]; function test($array) { foreach ($array as $k=>&$v) { if(is_array($v)) { test($v); } else { $v = 'five'; } } unset($v); } test($a); print_r($a); 

    1 answer 1

    Can. Only the indication that you pass the link should be in the function itself, and not on the variable. function test(&$array) otherwise warning in earlier versions, critical error in later versions.

    • merci, what you need - J. Doe