Good Day guys, Please issue on how best to manage my checkbox value in a for loop. first in the form below, people are only to check the Male checkbox if they are male and leave it if the are female. Now my issue is, if the last checkbox is checked, automatically it means only the value of that particular checkbox is set. this makes my php loop to assign it to the first looping data/result. Please how can i rectify this. Thanks in Advance
<form method="Post">
<input type="checkbox" name="male[]" >
<input type="text" name="name[]" >
<input type="checkbox" name="male[]" >
<input type="checkbox" name="name[]" >
<input type="checkbox" name="male[]" >
<input type="checkbox" name="name[]" >
</form>
<?php
$data ="";
for ($x=0; $x < sizeof($_POST['name']); $x++) {
$gender = (isset($_POST['male']) ? "Male" : "Female");
$data .=$_POST['name'][$x].'</br>';
$data .=$gender.'</br>';
};
echo $data;
?>
supposing the last checkbox in the form was checked, the above code outputs,
**Esther** Male
**John** Female
**Mark** Female
Whats happening is its passing the value of the last checked box since it was the only one selected. please how do i manage this