array_walk acting weird
Posted: Sun Jun 21, 2009 8:09 pm
Array_walk is not doing what it's supposed to do. Or maybe i'm not doing something right, either case have a look at this:
I have the function that is supposed to remove the [ and ] from a string given to it:
and an array that array_walk will apply the function to:
when I run array_walk($Array, 'stripbraces'); and then print_r($Array) it is the same as the original array??? I have &$String as the only parameter in the stripbraces function and the & is supposed to make array_walk apply it to the original array since its a reference so I don't know what's going on.
But yet when I do:
and call print_r($Array) it works perfectly fine.
I have the function that is supposed to remove the [ and ] from a string given to it:
Code: Select all
function stripbraces(&$String) {
return ltrim(trim($String, ']'), '[');
}Code: Select all
$Array = array('[test]', '[test2]', '[anothertest]');But yet when I do:
Code: Select all
foreach ($Array as $id => $tag) {
$Array[$id] = stripbraces($tag);
}