LoginSignup
19
20

More than 5 years have passed since last update.

[PHP] if文を短くする初歩的なやつ

Posted at

if文の条件式を短くしたくて、いろいろ探していたらこんなことに今更気づいてしまいました。
PHPマニュアル:issetのところ

複数のパラメータを渡した場合は、isset() はそれらすべてがセットされている場合にのみ TRUE を返します。 左から順に評価を行い、セットされていない変数があった時点で処理を終了します。

なんと.....知らなかったです。。。。:sweat_smile:

ということは下の条件式長いやつが、

条件式長いやつ
if (isset($hoge1) && isset($hoge2) && isset(hoge3)) {
    //なんらか処理
}

こんな感じにっ!!

条件式短いやつ
if (isset($hoge1, $hoge2, $hoge3)) {
    //なんらか処理
}

短くなって嬉しかったです:blush:

19
20
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
19
20