<?php #Syntex (if Condition) ? (stat1) : (stat2); #example $var1 = 5; $var2 = 2; echo $check = ($var1 > $var2) ? "right" : "wrong"; #output : right /* explination : if condition is true then display the stat1 and if condition is worng then display stat2 */ ?>
(Condition) ? (Statement1) : (Statement2);
<?php $marks=40; print ($marks>=40) ? "pass" : "Fail"; ?>
$result = $condition ? 'foo' : 'bar';
print ($marks>=40) ? "pass" : "Fail";
<?php $name = isset($_POST['Name'])?$_POST['Name']:null; $age = isset($_POST['Age'])?$_POST['Age']:null; ?>
<?php if(isset($_POST['Name'])) $name = $_POST['Name']; else $name = null; if(isset($_POST['Age'])) $age = $_POST['Age']; else $age = null; ?>
<?php $age = 20; print ($age >= 18) ? "Adult" : "Not Adult"; ?>
<?php $a = 10; $b = $a > 15 ? 20 : 5; print ("Value of b is " . $b); ?>
www.edureka.co