ไวยากรณ์มีดังนี้ −
$anyVariableName=yourCondition ? if condition becomes true then this will be executed: if condition becomes false then this gets executed;
ตัวอย่าง
รหัส PHP มีดังต่อไปนี้
<!DOCTYPE html> <html> <body> <?php $value=100; $result=$value >=100 ? "Greater Than or Equal to 100":"Less Than 100"; echo $result; ?> </body> </html>
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้
Greater Than or Equal to 100