Skip to content
Advertisement

Apply function to every element of a multidimensional array

I have a multidimensional array like this (please ignore the strlen):

JavaScript

And I want to call “strtoupper” for every element (Value1, Value2, etc.) on each level of the multidimensional array (document, etc.).

I tried array_walk_recursive($array, "strtoupper"); but it doesn’t work. But why, what can I do?

Advertisement

Answer

As strtoupper does not change the original value, but returns new value instead, you should do this:

JavaScript

Simple fiddle.

Also this hint is described in manual, see the note on callback parameter description.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement