How can i show value when checkbox was checked using loop for ?
.....................................................................................................................................................................
<form method="post">
<input type="checkbox" name="a_0" value="0">0
<input type="checkbox" name="a_1" value="1">1
<input type="checkbox" name="a_2" value="2">2
<input type="checkbox" name="a_3" value="3">3
<input type="checkbox" name="a_4" value="4">4
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST["submit"]))
{
for($i=0;$i<4;$i++)
{
if(${"_POST[a_{$i}]"} != '')
{ echo ${"_POST[a_{$i}]"}; }
else
{ echo "no"; }
}
}
?>
Change:
${"_POST[a_{$i}]"}
To:
$_POST['a_' . $i]
Or (note the double quotes):
$_POST["a_$i"]
Try like this:
<?php
if(isset($_POST["submit"]))
{
for($i=0;$i<4;$i++)
{
if(${"_POST[a_{$i}]"} != '')
{ echo $_POST['a_{$i}']; }
else
{ echo "no"; }
}
}
?>