0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHPで身長を比較する関数を作る

Last updated at Posted at 2020-07-11
<?php


  function tall($X, $x, $Y, $y) {
        if ($x > $y) {
        return $X;
      } else if ($x < $y) {
        return $Y;
      } else {
        return 'どっちも一緒';
      }
  }

  function answer($name) {
    if ($name === 'どっちも一緒'){
      echo 'どっちも一緒';
    } else {
      echo $name . 'の方が大きい';
    }
  }

  $A = '河合俊一';
  $B = 'ボブサップ';
  $a = 195;
  $b = 196;
   
  $tall = tall($A, $a, $B, $b);
 
  answer($tall);
?>

実行結果は

ボブサップの方が大きい

コード汚なかったり、
もうちょっといい書き方あるかも

ちなみに関数側の引数は仮引数で何を入れてもいいんだけど
実引数の変数名に合わせた方がいいのか、
関数側の値に合わせた変数を命名した方がいいのか...

どっちだろうか...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?