ternary if php code example
Example 1: ternary operator in php
<?php
$marks=40;
print ($marks>=40) ? "pass" : "Fail";
?>
Example 2: php ternary operator
(Condition) ? (Statement1) : (Statement2);
Example 3: php ternary
$result = $condition ? 'foo' : 'bar';
Example 4: if else if ternary php
var name = (variable === 1) ? 'foo' : ((variable === 2) ? 'bar' : 'baz');
Example 5: ternary in php
print ($marks>=40) ? "pass" : "Fail";
Example 6: php ternary shorthand
$y = $x ? "true" : "false";