#17. PHP Ternary Operator Statements

 Ternary Operator Statements

  • Using for single Statement.

Syntax:

(Condition)? True Statement 1 : False Statement 2

Run Code:

<?php

$x = 180;

//($x > 20) ? $y="Grater" : $y= "Smaller";  Or
//$y = ($x > 20) ? "Grater" : "Smaller";      Or
//$y = $x > 20 ? "Grater" : "Smaller";      Or
$y = "Value is :" . ($x > 20 ? "Grater" : "Smaller");

echo $y;
?>

Comments

Popular posts from this blog

#30. PHP Recursive Function