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

Double Not (!!) Operator ใน PHP


ใน Double not operator (!!) ตัวแรกคือ ! ใช้ negate ค่า ส่วนตัวที่สองคือ ! อีกตัว negate อีกครั้ง การ implement Double not operator ใน PHP โค้ดมีดังนี้ −

ตัวอย่าง

<?php 
    $str = "0.1"; 
    echo "Value = $str"; 
    $res = !!$str; 
    echo "\nDouble Negated Value = $res"; 
?>

ผลลัพธ์

จะผลลัพธ์ดังนี้ −

Value = 0.1 Double Negated Value = 1

ตัวอย่าง

มาดูตัวอย่างอีกอย่าง −

<?php 
    $str = "100.56"; 
    echo "String = $str"; 
    $num = floatval($str); 
    echo "\nNumber (Converted from String) = $num"; 
    $res = !!$num; 
    echo "\nDouble Negated Value = $res"; 
?>

ผลลัพธ์

จะผลลัพธ์ดังนี้ −

String = 100.56 Number (Converted from String) = 100.56 Double Negated Value = 1