I don't exactly understand what you want to do but I hope this will
help ypu getting your values:
<!-- *snip* -->
<html>
<form action="NewFile.php" method="POST">
<?
for($i=0;$i<5;$i++){
echo"<select name=\"test[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"2\">2</option>";
echo"<option value=\"3\">3</option>";
echo"</select>";
}
?>
<INPUT type="submit">
</form>
<?
# this will show you all values that are in $_POST
echo '<pre>', print_r($_POST), '</pre>';
# extract the array that contains all 5 values of the drop downs
$your_data = $_POST["test"];
# display the array
echo '<pre>', print_r($your_data), '</pre>';
# run through the array
foreach ($your_data as $value_from_array)
{
# ...and do with the values whatever you want to do
if ($value_from_array==5)
{
// instructions
# :-)
}
}
?>
</html>
<!-- *snap* -->
Leszek schrieb:
I have a form with 5 dropdown lists I want to put all selected values to an
array called $data[] so i wrote sometthing like this:
for(i=0;i<5;i++){
echo"<select name=\"\$data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}
So I think this will put all selected values into an array.
But the problem is that when user submits the form this array goes to $_POST
array
And I have no idea how to read a value from an array $data which is into
array $_POST and use it as a part of "if" statement
for example
if (value_from_array==5){
// instructions
}
Thanks for help
Leszek