Passing user data as reference to array_walk_recursive in Php

arrays, php, reference

Solution

According to the php documentation of anonymous functions inherited variables of a closure have to be defined in the functions header with the keyword `use` which leaves my example with:

function($value, $key) use (&$field) { ... }

Though the callback function inherits the parameters declared with `use` from its parent which means from the scope/function it has been declared (not executed) in.

Problem

I try to pass a third parameter via reference to Phps `array_walk_recursive` ``` $field = 'foo'; array_walk_recursive($config, function($value, $key, &$field) { $field = 'bar'; }, $field); echo $field // 'foo' ``` Why is `$field` still `'foo'`, though it has been passed to the function as reference?

Original source