<?

$checkboxes 
"";
$checkboxdata = array (
    
'firstbox' => 'First box label',
    
'secondbox' => 'Second box label',
    
'thirdbox' => 'Third box label',
    
'fourthbox' => 'Fourth box label',
    
'fifthbox' => 'Fifth box label'
);

foreach (
$checkboxdata as $value => $label) {
    if (isset(
$_POST['boxes']) && is_array($_POST['boxes']) && in_array($value$_POST['boxes'])) {
        
$checkboxes .= "<input name='boxes[]' type='checkbox' value='$value' checked='checked'> $label<br />\n";
    } else {
        
$checkboxes .= "<input name='boxes[]' type='checkbox' value='$value'> $label<br />\n";
    }
}

?>
<html>
    <body>
        <form method="post" action="<?= $_SERVER['PHP_SELF'?>">
            <?= $checkboxes ?>
            <input type="submit" />
        </form>
    </body>
</html>