Hello, all.
I have what I thought was a very simple for loop that cycles 5 times, then uses a very simple if..else to compare the numerical value of the current loop against the values in an array. If the two match, it packs a certain line of html into an array before looping again. If it doesn't match, it packs a different line of html into the array and loops again.
Here's the code:
for($n=1;$n<6;$n++) {
$name = //the name value;
$value = //an array of several integers;
foreach($value as $val) {
if($val == $n) {
//Add checked checkbox code to array
$hsa_inputs[$n] = "<input type='checkbox' name='$name' value='$val' checked='checked' />";
}else{
//Add unchecked checkbox code to array
$hsa_inputs[$n] = "<input type='checkbox' name='$name' value='$n' />";
}//endelse
}//end foreach
}//end for
The problem is that when the script runs, only the LAST value in the $value array is cranking out the "checked checkbox" html code.
I plugged a print_r($val) inside the if...else to make sure that the $values array contains the numbers it should, and it is showing the correct (and multiple) values that belong there, yet the first value is still adding the "unchecked checkbox" html.
Does anybody see anything blaringly wrong that might be the cause of this weird behavior? It seems like such a basic script and yet it is driving me insane. Please help.
Best,
cEM