2011-01-19 83 views

回答

17

==檢查兩個操作數的值是否相等。 ===檢查值以及兩個操作數的類型。

if("1" == 1) 
    echo "true"; 
else 
    echo "false"; 

以上將輸出true

if("1" === 1) 
    echo "true"; 
else 
    echo "false"; 

以上將輸出false

if("1" === (string)1) 
    echo "true"; 
else 
    echo "false"; 

以上將輸出true

1

最簡單的顯示方式是使用字符串。舉兩個例子:

echo ("007" === "7" ? "EQUAL!" : "not equal"); 
echo ("007" == "7" ? "EQUAL!" : "not equal"); 
1

除了@ DavidT的例子,一個更實際的例子是:

$foo = "Goo"; 
$bar = "Good Morning"; 
if (strpos($bar,$foo)) 
    echo "Won't be seen, returns false because the result is in fact 0"; 
if (strpos($bar,$foo) !== false) 
    echo "True, though 0 is returned it IS NOT false)"; 
相關問題