Answers for "php nested ternary operator"

PHP
1

php nested ternary operator

// The below statement is an exaple of the nested ternary operator in PHP
echo ($row["position"] != "NA") ? $row["position"] : 
(($row["current_degree"] != "NA") ? $row["current_degree"] : 
 $row["qualification"]);

// The equivalent if else structure is given below

if ($row["position"] != "NA"){
  echo $row["position"];
} elseif($row["current_degree"] != "NA"){
  echo $row["current_degree"];
} else{
  echo $row["qualification"];
}
Posted by: Guest on June-26-2021

Browse Popular Code Answers by Language