Articles → PHP → Ternary Operator In PHP
Ternary Operator In PHP
Software Requirement
- XAMPP is installed on your machine
- Any text editor like Notepad
Technical Knowledge
What Is A Ternary Operation?
- First argument is the comparison argument
- Second argument is the result of a true comparison
- Third argument is the result of a false comparison
Syntax
Comparison? result of true comparison : result of false comparison;
Why Should I Use Ternary Operator?
if($age < 18)
echo("Not eligible to vote");
else
echo("Eligible to vote");
echo ($age < 18?"Not eligible to vote":"Eligible to vote");