チェックボックス:連想配列


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>商品の一覧をチェックボックスに表示する</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrap">
<div id="head">
<h1>商品の一覧をチェックボックスに表示する</h1>
</div>
<div id="content">
<div style="margin-top: 200px">
<form action="" method="get">
<dl>
<dt>商品</dt>
<dd>
<?php
$items = array('a-1'=>'ガム', 'b-1'=>'チョコレート', 'c-3'=>'クッキー');

foreach($items as $itemKey => $itemValue) {
	print ('<input type="checkbox" id="' . $itemKey . '" value="' . $itemKey . '" /><label for="' . $itemKey . '">' . $itemValue . '</label> ');
}
?>
</dd>
</dl>
<input type="submit" value="送信する">
</form>
</div>
</div>
</div>
</body>
</html>