ternary operator if else if php code example
Example 1: ternary operator in php
<?php
$marks=40;
print ($marks>=40) ? "pass" : "Fail";
?>
Example 2: php ternary operators
// Both ternary and if/else returns the same result
// ternary
$result = $condition ? 'foo' : 'bar';
// if/else
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}