shorthand php if{} ELSE IF{} else{} [duplicate] shorthand php if{} ELSE IF{} else{} [duplicate] php php

shorthand php if{} ELSE IF{} else{} [duplicate]


You're looking for ternary statements.

Syntax:

$condition ? $value_if_true : $value_if_false

Syntax for nested ternary statements:

$a ? $b : ( $c ? $d : ( $e ? $f : $g ) )

Just a warning, nested ternary statements are hard to read, so it's recommended to unnested ternary statements.


You can see this Ternary operator. Good when you have an if/else, but bad readability if you do more.

Alternative syntax. This syntax is useful when you use html/php in the same code. It helps us to see the end of if/foreach/while...

switch/case. The best is probably to post some code to see if it could be shortened.