問題 1

次のプログラム( choice_tr1.php )があります。

choice_tr1.php

<?php
$age = 20;

# TODO

以下のルールのとおり動作するプログラムを作成してください。

$age 出力内容
20以上 "YES" と出力する
20未満 "NO" と出力する

実行結果: $age が20以上の場合

$ php choice_tr1.php
YES

実行結果: $age が20以下の場合

$ php choice_tr1.php
NO

プログラムを作成後 $age 変数の値を変更して動作確認してください。


問題 2

次のプログラム( choice_tr2.php )があります。

choice_tr2.php

<?php
$userame = "Alice";
$password = "secret";

# TODO

以下のルールのとおり動作するプログラムを作成してください。

  • $username が "Alice" かつ $password が "secret" の場合
    • "OK" と出力する
  • 上記以外の場合( $username が "Alice" かつ $password が "secret" でない場合)
    • "ERROR" と出力する

実行結果: $username が "Alice" かつ $password が "secret" の場合

$ php choice_tr2.php
OK

実行結果: 上記以外の場合

$ php choice_tr2.php
ERROR

プログラムを作成後 $username 変数、 $password 変数の値を変更して動作確認してください。


問題 3

次のプログラム( choice_tr3.php )があります。

choice_tr3.php

<?php
$height = 200;
$width = 100;

# TODO

以下のルールのとおり動作するプログラムを作成してください。

  • $height$width の大きい方の値を出力する

実行結果: $height が200、 $width が100の場合

$ php choice_tr3.php
200

実行結果: $height が100、 $width が150の場合

$ php choice_tr3.php
150

プログラムを作成後 $width 変数、 $height 変数の値を変更して動作確認してください。


問題 4

次のプログラム( choice_tr4.php )があります。

choice_tr3.php

<?php
$ages = [10, 20 , 30];

# TODO

以下のルールのとおり動作するプログラムを作成してください。

$ages 配列の要素 出力内容
20以上 "YES" と出力する
20未満 "NO" と出力する

実行結果

$ php choice_tr3.php
NO
YES
YES

$ages 配列の要素が 102030 のため、それぞれ "NO"、 "YES"、 "YES" とします。


問題 5

次のプログラム( choice_tr5.php )があります。

choice_tr5.php

<?php
$numbers = [20, 30, 25, 35, 30];
$max = 0;

# TODO

echo $max;

以下のルールのとおり動作するプログラムを作成してください。

  • $numbers 配列の要素の最大値を出力する

実行結果

$ php choice_tr5.php
35