配列の要素数を取得、count

配列の要素数を調べるときには、count関数を使う

<?php 
  $city[0] = '東京';
  $city[1] = '名古屋';
  $city[2] = '京都';
  $city[3] = '大阪';
  $city[4] = '福岡';
?>

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>配列の要素数を知る</title>
</head>
<body>
<table border="1" width="100">
<tr><th>都市名</th></tr>
<?php
for($i = 0; $i < count($city); $i++){
 print'<tr><td>'.$city[$i].'</td></tr>'."\n";
}
?>
</table>
</body>
</html>