LoginSignup
7
7

More than 5 years have passed since last update.

if文の三項演算子

Posted at

条件式 ? 式1 : 式2

条件式を評価し、TRUEであれば式1、FALSEであれば式2を返します。

//基本形
$check = ($message = 'hi') ? 1 : 0;
//応用系
$user->setAreaId(((int)$request->get('areaId')) ?: $user->getAreaId())
7
7
1

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