php ternary operator
snippet in php

php ternary operator

user2712

<?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
*/
?>

php ternary operator

user6686

(Condition) ? (Statement1) : (Statement2);

php ternary operator

user7977

<?php 
$age = 20; 
print ($age >= 18) ? "Adult" : "Not Adult"; 
?> 

php ternary operator

user9461

<?php 
if(isset($_POST['Name'])) 
    $name = $_POST['Name']; 
else
    $name = null; 
  
if(isset($_POST['Age'])) 
    $age = $_POST['Age']; 
else
    $age = null; 
?> 

php ternary operator

user8169

<?php 
$a = 10; 
$b = $a > 15 ? 20 : 5; 
print ("Value of b is " . $b); 
?> 

php ternary operator

user3383

<?php 
$name = isset($_POST['Name'])?$_POST['Name']:null;  
$age = isset($_POST['Age'])?$_POST['Age']:null;  
?>