Ternary Operator in Php


Ternary operator is simply short form of if/else statement. Ternary operator is also known as SHORTHAND operator.
The logic of using the Ternary operator is  " (condition) ? true statement : false statement "
Example :-
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
$a = 20;   
$b = 10;   
$example = ($b > $a) ? "B is greater" : "A is greater";
echo $example;
?>
</body>
</html>

Output of the above code
A is greater

No comments: