Afficher un message
Vieux 15/06/2007, 04h38   #3
Gleep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Perform the same action(s) on a variable number of POST variables

On Thu, 14 Jun 2007 23:42:36 +0200, Michael Fesser <netizen@gmx.de> wrote:

>.oO(joboils@hotmail.com)
>
>>Hope some of the gurus around here can me stop feeling stupid.
>>Is there some way to have the same actions (like, say, STR_REPLACE(),
>>TRIM() or STRTOUPPER(), and stuff like that) operate on all the
>>variables passed by POST from a range of web forms without writing
>>these actions specifically for each form's variables?

>
>foreach?
>
>Micha



yup, treat $_POST as you would an array because it is an array

example
foreach($_POST as $key => $item)
{
$$key = trim($_POST[$key]);
}

key is a variable variable

it would be the equivalent of this

$apple = $_POST['apple'];
$orange = $_POST['orange'];
$pear = $_POST['pear'];

etc..

with the loop above you don't have to go thru the process of calling each one out
it's done throu the loop - hope that makes sense


  Réponse avec citation
 
Page generated in 0,05511 seconds with 9 queries