Jessica Posted December 20, 2007 Share Posted December 20, 2007 I have tried both: array_walk(&$files, 'htmlentities'); array_walk($files, 'htmlentities'); Using PHP5 Nothing changes, it still prints & instead of & Do I have to wrap htmlentities in a in a custom function or am I doing something wrong? EDIT: I tried wrapping it in a function and no change. $h = create_function('$txt', 'return htmlentities($txt);'); array_walk(&$files, $h); print_r($files); Array ( [28] => panels/DC_air & space #2.jpg [29] => panels/DC_air & space #3.jpg [30] => panels/DC_air & space.jpg ) Quote Link to comment https://forums.phpfreaks.com/topic/82437-cant-get-array_walk-to-show-changes-to-array/ Share on other sites More sharing options...
teng84 Posted December 20, 2007 Share Posted December 20, 2007 <?php $array = array("d" => "lemon", "a" => "<br>"); function alter(&$item1, $key){ $item1 = htmlentities($item1); } array_walk($array, 'alter'); print_r($$array); ?> maybe Quote Link to comment https://forums.phpfreaks.com/topic/82437-cant-get-array_walk-to-show-changes-to-array/#findComment-419159 Share on other sites More sharing options...
Jessica Posted December 20, 2007 Author Share Posted December 20, 2007 You have an extra $ in there, but after I removed it it still didn't work. Still got: [28] => panels/DC_air & space #2.jpg [29] => panels/DC_air & space #3.jpg [30] => panels/DC_air & space.jpg Quote Link to comment https://forums.phpfreaks.com/topic/82437-cant-get-array_walk-to-show-changes-to-array/#findComment-419168 Share on other sites More sharing options...
tibberous Posted December 20, 2007 Share Posted December 20, 2007 I think your problem is that htmlentities doesn't change the string it returns it. You aply the function to every member in the array, but the function doesn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/82437-cant-get-array_walk-to-show-changes-to-array/#findComment-419192 Share on other sites More sharing options...
tibberous Posted December 20, 2007 Share Posted December 20, 2007 This works: <?php $arr = array('panels/DC_air & space #2.jpg', 'panels/DC_air & space #3.jpg', 'panels/DC_air & space.jpg'); function alter(&$arr_item){ $arr_item = htmlentities($arr_item); } array_walk($arr, 'alter'); print_r($arr); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82437-cant-get-array_walk-to-show-changes-to-array/#findComment-419194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.