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

PHP三項演算子

Posted at

書式

三項演算子
条件式 ? 式1 : 式2 ;

条件式が真であれば式1を実行し、偽であれば式2を実行する。
if(条件式) then 式1 else 式2」と同じ

真の場合
$num = 2;
$val = $num % 2 == 0 ? echo '偶数です' : echo '奇数です';
echo $val;
実行結果
偶数です

まとめ

はじめに条件式を評価し、式の結果がTRUEの場合は真の式を返し、結果がFALSEの場合は偽の式を返します。

参考

【PHP入門】三項演算子とは?使いこなしてコードをスッキリする


著者: E.R (株式会社ウィズツーワン)
5
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
5
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?