How to use Conditional Operator in PHP
In this article, I will explain how the Conditional operator can be used in PHP.
PHP language supports following type of operators.
- Arithmetic Operators
- Comparison Operators
- Logical (or Relational) Operators
- Assignment Operators
- Conditional (or ternary) Operators
The Conditional operators are summarized in the following table.
||If Condition is true ? Then value X : Otherwise value Y
$x = 20;
$y = 30;
$result = ($x > $y ) ? $x :$y;
echo "Test Result1 : Value of result is $result<br/>";
$result = ($x < $y ) ? $x :$y;
echo "Test Result2 : Value of result is $result<br/>";
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here