I have a multidimensional associative array, and I want to apply array_walk_recursive so that I can execute a function on every single value.
However, whenever a key is named "special" I want to execute a different function.
So if the array is like this:
$array = array('a' => 'apple', 'b' => 'banana', 'special' => 'xylophone', 'c' => 'cherr开发者_JAVA技巧y');
Then I want to execute function doThis() on 'a', 'b', and 'c', and I want to execute doThat() on 'special'.
Is this possible?
(Note: my example is a simple array, but the real code needs to act on multidimensional array)
Your function gets passed the key as the second argument:
function foo(&$item, $key) {
if ($key == 'special') {
return doThat($item, $key);
}
return doThis($item, $key);
}
精彩评论