PHPの教科書7 foreach

foreachを使用して、配列のパラメータを順番に取得していく
http://felica.boy.jp/textbook/lecture1-2-3.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>よく分かるPHPの教科書</title>
</head>

<body>
<p>foreach文</p>
<select name="pref" id="pref">
<?php
//foreachを使って、配列を順番に代入
$prefs = array('北海道','東北','北陸','関東','中部','近畿','中国','四国','九州','沖縄','削除');
//array_popで最後の配列の値を削除
array_pop($prefs);

foreach($prefs as $pref) {
	print('<option value="' .$pref. '">' .$pref. '</option>');
}
?>
</select>
<br>
<p>for文</p>
<select name="pref" id="pref">
<?php
//for文とcount関数を使って、10個の配列を順番に取得
//count関数は、配列の数を取得
for($i=0; $i<count($prefs); $i++) {
	print('<option value="' .$prefs[$i]. '">' .$prefs[$i]. '</option>');
}
?>
</select>
<br>
<p>while文</p>
<select name="pref" id="pref">
<?php
$i=0;
while($i<count($prefs)) {
	print('<option value="' .$prefs[$i]. '">' .$prefs[$i]. '</option>');
	$i++;
}
?>
</select>
</body>

</html>