LoginSignup
0
0

More than 3 years have passed since last update.

if文の省略記法

Posted at
from.php
$area = '京都';

//A
$from = isset($area) ? '出身は' . $area . 'です' : '出身地が設定されてません';

//B
if (isset($area)) {
    $from = '出身は' . $area . 'です';
} else {
    $from = ',出身地が設定されてません';
}

Aの書き方とBの書き方ではどちらも同じ結果が$fromに代入されることになります。
初学者の自分はBの表記法でしかしたことなかったですが、Aの表記法の方が断然すっきりしますね。

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