Re: applying one function to all array elements

From: Date: Mon, 03 Nov 2003 05:32:34 +0000
Subject: Re: applying one function to all array elements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168373@lists.php.net to get a copy of this message
--- Justin French <justin@indent.com.au> wrote: > Can someone show me a simple, clean way to apply one function (eg > stripslashes()) to every element in an array (eg $_POST)? [snip] > I've also seen http://www.php.net/array_walk, but > couldn't > determine how/if it suited my needs. Maybe you can explain how your need is not met with array_walk()? That would be my suggestion, since it seems to do exactly what you want, but then you mention that you have already looked at it. It does require that the function take two parameters, which isn't the case with stripslashes(). So, you can make a very tiny wrapper function that discards the second parameter (since you don't need it): <? function array_stripslashes(&$var, $key) { $var = stripslashes($var); } array_walk($_POST, 'array_stripslashes'); ?> Hope that helps. Chris ===== My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp

« previous php.general (#168373) next »