Control Flow Details
Ternary Choice
The ternary operator chooses between two expressions.
Ternary Choice
ternary_choice.php
<?php
$age = ;
$ticket = $age >= 18 ? "adult" : "child";
$price = $ticket === "adult" ? 12 : 6;
echo "age=" . $age . "\n";
echo "ticket=" . $ticket . "\n";
echo "price=" . $price . "\n";
<?php
$age = ;
$ticket = $age >= 18 ? "adult" : "child";
$price = $ticket === "adult" ? 12 : 6;
echo "age=" . $age . "\n";
echo "ticket=" . $ticket . "\n";
echo "price=" . $price . "\n";
<?php
$age = ;
$ticket = $age >= 18 ? "adult" : "child";
$price = $ticket === "adult" ? 12 : 6;
echo "age=" . $age . "\n";
echo "ticket=" . $ticket . "\n";
echo "price=" . $price . "\n";
ternary
`condition ? a : b` returns `a` when the condition is true, otherwise `b`.