Php – array_walk or array_map


I'm currently using array_map to apply callbacks to elements of an array. But I want to be able to pass an argument to the callback function like array_walk does.
I suppose I could just use array_walk, but I need the return value to be an array like if you use array_map, not TRUE or FALSE.

So is it possible to use array_map and pass an argument to the callback function? Or perhaps make the array_walk return an array instead of boolean?

Best Solution

You don't need it to return an array.

Instead of:

$newArray = array_function_you_are_looking_for($oldArray, $funcName);


$newArray = $oldArray;
array_walk($newArray, $funcName);