php ternary else if code example
Example 1: php ternary operator
(Condition) ? (Statement1) : (Statement2);
Example 2: if else if ternary php
var name = (variable === 1) ? 'foo' : ((variable === 2) ? 'bar' : 'baz');
Example 3: 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'
}
Example 4: ternary in php
print ($marks>=40) ? "pass" : "Fail";