Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP ทำไม && ไม่ trigger เป็น false

เพราะถ้าใช้ && ทั้งสองเงื่อนไขต้องเป็น true หากเงื่อนไขใดเป็น false เงื่อนไขรวมจะประเมินเป็น false

โค้ด PHP ดังนี้ -

ตัวอย่าง

<!DOCTYPE html> <html> <body> <?php 
    $firstCondition= "John"; 
    $secondCondition = "David"; 
    if ($firstCondition == "John" && $secondCondition == "David" && ($firstCondition == "Mike" || $firstCondition == "John")) { 
        echo "The above condition is true"; 
    } else { 
        echo "The above condition is not true"; 
    } 
?> </body> </html>

ผลลัพธ์

The above condition is true