How to retain the value of check boxes using array ?
If we have 4 or more check boxes . then it is little difficult to maintain different names for checkboxes.
the best way is to use array as name of checkbox. (in_array function)
Example :
<input name=”n1[]” value=”Art” type=”checkbox” <? if (in_array(”Art”,$_POST[n1])) echo “checked”; ?>> Art<br>
<input name=”n1[]” value=”Fashion” type=”checkbox” <? if (in_array(”Fashion”,$_POST[n1])) echo “checked”; ?>> Fashion<br>
<input name=”n1[]” value=”Film” type=”checkbox” <? if (in_array(”Film”,$_POST[n1])) echo “checked”; ?>> Film<br>
<input name=”n1[]” value=”Music” type=”checkbox” <? if (in_array(”Music”,$_POST[n1])) echo “checked”; ?>> Music<br>
so when you post now the checks will be retained.
Posted by Suresh B