Cú pháp như sau:
$anyVariableName = yourCondition ? if condition becomes true then this will be executed : if condition becomes false then this gets executed;
Ví dụ
Mã PHP như sau:
<!DOCTYPE html> <html> <body> <?php $value = 100; $result = $value >= 100 ? "Greater Than or Equal to 100" : "Less Than 100"; echo $result; ?> </body> </html>
Kết quả
Đoạn mã trên sẽ cho kết quả sau:
Greater Than or Equal to 100