php - How can i show value when checkbox was checked using loop for? -
how can show value when checkbox checked using loop ?
.....................................................................................................................................................................
<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 double quotes):
$_post["a_$i"]
php post for-loop
No comments:
Post a Comment