This is what I have:
$prevtag = "1,2,5";
$arr;
$arr["1"] = "BOOKS";
$arr["2"] = "MAGAZINES";
$arr["3"] = "PAMPHLETS";
$arr["4"] = "CD'S";
$arr["5"] = "DVD'S";
And I need to check if any of $prevtag exists in $arr and then echo 5 checkboxes:
foreach ($arr as $key => $value) {
$checked = in_array($prevtag,$arr) ? '' : 'checked="checked"';
echo "<input name=\"txtTags".$key."\" type=\"checkbox\" id=\"txtTags".$key."\" value=\"on\" $checked />\n";
echo "<label for=\"txtTags".$key."\">".$value."</label>\n";
}
But I'm getting all checked and not just the ones in $prevtag - What am I doing wrong?