Looktrne Posted June 2, 2009 Share Posted June 2, 2009 I have a function that is a bit corrupted could anyone tell me how to make this a working function? thanks in advance Paul function array_addslashes( $arr ) { foreach ( $arr as $key => $UNKNOWN ) { if ( is_array( $UNKNOWN ) ) { $arr [$key] = array_addslashes( $UNKNOWN); } else { $arr [$key] = addslashes( $UNKNOWN ); } } return $arr; } $UNKNOWN needs to be a variable but I am not sure on what it should be thanks for any tips on this Paul Link to comment https://forums.phpfreaks.com/topic/160565-need-help-with-this-function/ Share on other sites More sharing options...
Andy-H Posted June 2, 2009 Share Posted June 2, 2009 You could look into using http://php.net/array_map ?? Link to comment https://forums.phpfreaks.com/topic/160565-need-help-with-this-function/#findComment-847415 Share on other sites More sharing options...
Ken2k7 Posted June 2, 2009 Share Posted June 2, 2009 I'm not exactly sure what you want to do. You didn't state the purpose of the function. I assume you mean this - <?php function array_addslashes ($arr) { foreach ($arr as $key => $val) { if (is_array($val)) $arr[$key] = array_addslashes($val); else $new_arr[$key] = addslashes($val); } return $arr; } Link to comment https://forums.phpfreaks.com/topic/160565-need-help-with-this-function/#findComment-847418 Share on other sites More sharing options...
Looktrne Posted June 2, 2009 Author Share Posted June 2, 2009 thanks I will try that the problem is I dont know what the function does just need the missing variable I will see if $val does it Paul Link to comment https://forums.phpfreaks.com/topic/160565-need-help-with-this-function/#findComment-847457 Share on other sites More sharing options...
Andy-H Posted June 2, 2009 Share Posted June 2, 2009 Thats why I linked it to the manual lol You could also try imploding the array into a string and using addslashes on the string before exploding it back into an array, the index's will be reset tho function array_addSlashes( $arr ) { $arr = implode(",", $arr); $arr = addSlashes($arr); return explode(",", $arr); } Link to comment https://forums.phpfreaks.com/topic/160565-need-help-with-this-function/#findComment-847481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.