Posted by rich on 09/20/06 12:52
I have 2 arrays. I am trying to use in_array with and it doesn't seem
to be working. I have done a print_r of each one for my test data.
Array $primsecA is below:
Array ( [0] => Array ( [primsecid] => 1 [primsec] => Primary ) [1] =>
Array ( [primsecid] => 2 [primsec] => Secondary ) [2] => Array (
[primsecid] => 3 [primsec] => Skin Protectors ) )
Array $specprimA is below.
Array ( [0] => Array ( [primsecid] => 1 ) [1] => Array ( [primsecid] =>
2 ) )
Now here is the logic for checked fields.
$numcl= count($primsecA);
for ($i=0; $i<$numcl; $i++){
$primsec = $primsecA[$i]['primsec'];
$primsecid = $primsecA[$i]['primsecid'];
if (sizeof($specprimA)==0 || !is_array($specprimA)){?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}else{
if (in_array($primsecid, $specprimA)) { ?>
<input type="checkbox" checked="checked" tabindex="2"
name="primsecid[]" value="<?php echo $primsecA[$i]['primsecid'];
?>"/><?php echo $primsecA[$i]['primsec'];
} else { echo ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
}
}?>
In the above code I want the field to be checked if its in the
$specprimA array. None of the fields are being checked. any ideas?
Navigation:
[Reply to this message]
|