Articles → PHP → Ternary Operator In PHP

Ternary Operator In PHP






Software Requirement




  1. XAMPP is installed on your machine
  2. Any text editor like Notepad

Technical Knowledge





What Is A Ternary Operation?




  1. First argument is the comparison argument
  2. Second argument is the result of a true comparison
  3. 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");





Posted By  -  Karan Gupta
 
Posted On  -  Monday, October 13, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250