I had some problems using this function - it didn't want to apply PHP-defined functions. So I decided to write my own - here it is. I had to use some generic-programming skills, didn't really checked the speed (I think it could be slow)... I believe it could be much better, but I don't know, how - well, I guess multiple array support and recursion would be nice. So?
Prototype:
bool arrayWalk(array &$arry, callback $callback, mixed $params=false)
<?php
function arrayWalk(&$arry, $callback, $params=false) {
$P=array(""); $a=""; if($params !== false) { if(is_array($params)) { foreach($params as $par)
{ $P[]=$par; }
}
else { $P[]=$params; }
}
for( $i=0; isset($P[$i]); ++$i
)
{ $a.='$'.chr($i + 97).', '; } $a=substr($a, 0, -2); $func=create_function($a, 'return '.$callback.'('.$a.');'); if(is_callable($func)) {
for( $i=0; isset($arry[$i]); ++$i
) {
$P[0]=$arry[$i]; $arry[$i] = call_user_func_array($func, $P); }
}
else
{ return false; } return true; } ?>
One big problem I've noticed so far - for example, if you wanted to use str_replace on the array, you'd fail - simply because of the arguement order of str_replace, where the string modified is the third arguement, not the first as arrayWalk requires.
So, still some work left...