dimanche 25 avril 2021

How can I write echo and return inside of PHP ternary operator?

<?php
$glass= "water";
$bottol;`enter code here`

if(isset($glass)){
    echo $glass;
}elseif(isset($bottol)){
    echo "Empty Bottol";
}
echo PHP_EOL;

Ternary Operator is bellow

$demo = isset($glass) ? $glass : $bottol;
echo $demo;

But how can I echo the $glass variable as like as if/else statements inside the ternary operator?? Is it possible? Also, how can I return the $glass variable inside the ternary operator? Like: return $glass

?>

Aucun commentaire:

Enregistrer un commentaire