I have an array and want to iterate it and apply a class method to every element. For this purpose one can use array_map(...)
or array_walk(...)
. If it's a multidimensional array, array_walk_recursive(...)
can be used.
What I have now is following case:
Array (
[form_fieldset_aaa] => Array (
[form_element_bbb] => Array (
[validation_error_type_foo] => error message...
)
[form_fieldset_ccc] => Array (
[form_fieldset_ddd] => Array (
[form_fieldset_eee] => Array (
[form_element_fff] => Array (
[validation_error_type_bar] => error message...
)
)
)
[form_fieldset_ggg] => Array (
[1] => Array (
[form_fieldset_hhh] => Array (
[validation_error_type_buz] => error message...
)
)
)
)
)
)
- a multidimensional (associative) array;
- a method, that needs to be applied to every element (recursively);
- the method needs to get not only the current
key
andvalue
, but also the additional information like thekey
andvalue
of the parent element and an object for$newObject = $object->get($parentKey)
.
How to implement that requirement?