Page 1 of 1

how to handle multiple variables

Posted: Tue Apr 07, 2009 5:48 am
by aneuryzma
How can I refer to all variables of a POST string using PHP ?

$_POST['var0']
$_POST['var1']

what if I don't know the names var0, var1.. and how many they are ?

thanks

Re: how to handle multiple variables

Posted: Tue Apr 07, 2009 5:50 am
by Apollo

Code: Select all

foreach($_POST as $k => $v) { print("['$k'] = $v, "); }

Re: how to handle multiple variables

Posted: Tue Apr 07, 2009 6:43 am
by aneuryzma
thanks, I still have one question:

if this is my POST:
dropDown0=1&dropDown1=1&dropDown2=1
and this is my code:

Code: Select all

 
 
 
    $fname = "form.xml";
 
    $fhandle = fopen($fname,"w");
    
    foreach($_POST as $entry => $value) {
    
        if ($entry!="dataFormat") fwrite($fhandle, "<$entry> $value </$entry> \n");
    
    }
    
    fclose($fhandle);
 
 
 

why do my output is inverted ? (dropDown2 is before dropDown1)

Code: Select all

 
<dropDown0> 1 </dropDown0> 
<dropDown2> 1 </dropDown2> 
<dropDown1> 3 </dropDown1>
 

Re: how to handle multiple variables

Posted: Tue Apr 07, 2009 6:50 am
by Apollo
No clue, probably depends on your webserver and PHP settings. But it's easily taken care of with

Code: Select all

ksort($_POST);
See also the manual.