Files
php-question-answer/Question01-StartProgram/Ex05.php
2026-10-09 12:33:29 +09:00

26 lines
788 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// TODO: 配列keywordを定義し 「'平', '島', '沼', '山', '森'」 を代入してください
$keyword = ['平', '島', '沼', '山', '森'];
// TODO: 配列keywordに格納されている「沼」のみを表示してください
echo $keyword[2];
// 【+αチャレンジ】
// 第4章で学ぶ「制御構文」を使うと、もっと簡単に書けます!
// まだ学んでいないけど、調べて挑戦してみよう!
// 答え
// ↓
// // 方法①: for ループを使う
// for ($i = 0; $i < count($keyword); $i++) {
// if ($keyword[$i] === '沼') {
// echo "<br>" . $keyword[$i];
// }
// }
// // 方法②: foreach を使う
// foreach ($keyword as $word) {
// if ($word === '沼') {
// echo "<br>" . $word;
// }
// }