
The default value is the first radio button.
The output like this: 1=>Y ,2=>N ,3=>N
OK, no problem.
Now my question is, I want to click the third radio button.
The expected output like this: 1=>N, 2=>N, 3=>Y
But my output like this: 1=>N, 2=>Y, 3=>Y
The second one should be N, not Y.
Here is my code:
<html>
<body>
<form action="test.php" method="post">
<?php
$defaultkey = array("Y","N","N");
for($i = 1; $i <= count($defaultkey); $i++)
{
?>
<input type="radio" name="choice" value="<?php echo $defaultkey[$i-1]; ?>"><?php echo $defaultkey[$i-1];?><br />
<?php
}
?>
<input type="submit" name="submit" value="OK" />
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
if($_POST['choice']=="Y")
{
for($j = 1; $j <=count($defaultkey); $j++)
{
echo ($j). '=>' .$defaultkey[$j-1]. '<br />';
}
}
else if($_POST['choice']=="N")
{
for($k = 1; $k <=count($defaultkey); $k++)
{
if($_POST['choice']==$defaultkey[$k-1])
{
$defaultkey[$k-1] = "Y";
echo ($k). '=>' .$defaultkey[$k-1]. '<br />';
}
else
{
$defaultkey[$k-1] = "N";
echo ($k). '=>' .$defaultkey[$k-1]. '<br />';
}
}
}
}
How should I solve it?
N, what should be the order then?