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 1 year has passed since last update.

三項演算子とは?

Posted at

この記事では
php7.4.21
Database server: MySQL Version 5.7.34
を使っています。

三項演算子を使うことで、if分を簡略化することができる。
例:

if分の場合
$array[
'key' = 10,
];

if(isset($arry['key'])){
$arry['key'] = *10;
}else{
$arry['key'] = 1;
}

三項演算子を使った場合
$array[
'key' = 10,
];
$arry['key'] = isset($arry['key']) ? $arry['key'] * 10 : 1;

三項演算子を使うと、if分の箇所が1行に簡略化できた。
どこにどの値が入ってるのかは、以下の通り。

値の出力先 = 条件式 ? Trueの場合の値 : Faulseの場合の値;

配列の初期化や変数の初期化の際によく使われる。

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?