Operators


Conditional Operator

Operator Sign Syntax Additional Information
Ternary ? : (expr) ? $a : $b evaluates to $a if expr evaluates to TRUE,
and $b if expr evaluates to FALSE
<?php
    $var1 = $var2 = 1;
    $var3 = ($var1 == $var2) ? true : false;
    $var4 = ($var1 != $var2) ? true : false;
    echo (int)$var3, "\r\n";
    echo (int)$var4;
?>
[result]  
1
0

※ It is recommended that you avoid "stacking" ternary expressions because PHPoC's behavior when using more than one ternary operator within a single statement is non-obvious.