2009-12-24 24 views
0

當我使用''反對""時,它會產生什麼影響?當我使用「'對抗」「時,它有什麼不同?

例如:

$example = 'Merry Christmas in Advance'; 
$eg = "Merry Christmas"; 

echo "$example"; 
echo '$example'; 


echo "$eg"; 
echo '$eg'; 

會是什麼樣的輸出爲每個print語句,我們能推斷'' VS在PHP""

+6

不試圖成爲這裏的咧嘴笑,但有1mil + http://www.google.com/search?q=single+quotes+vs+double+quotes+in+php的結果 – 2009-12-24 17:00:28

+0

您無法找到的位置文檔或自己運行該代碼? – mk12 2009-12-24 17:44:07

回答

6
$example = 'Merry Christmas in Advance'; 
$eg = "Merry Christmas"; 

echo "$example"; 
echo '$example'; 

echo "$eg"; 
echo '$eg'; 

會產生:

Merry Christmas in Advance$exampleMerry Christmas$eg

韓國人

Single quoted strings從字面上來看。沒有特殊字符(如\n)或變量被內插。

Double quoted strings將內插您的變量和特殊字符並相應地呈現它們。

+0

+1,簡潔的答案。我喜歡。 – 2009-12-24 21:24:22

3

單引號變量需要逐字輸入,雙引號解釋特殊字符的轉義序列並展開變量。

您可以在這裏看到一些很好的例子:http://php.net/manual/en/language.types.string.php

請注意,某些轉義序列仍然單引號內解釋。例如:

//輸出:阿諾德曾經說過: 「我會回來 」

回聲 '阿諾德曾經說過:「我\' LL 回來「」;

+0

很多信息可以在php.net上找到:http://us.php.net/manual/en/language.types.string.php – CalebD 2009-12-24 17:00:39

0

雙引號內插變量。

2

還可以包括雙引號和那些將被解釋爲變量內部變量,而不是字符串

所以:

$variable = 1; 
echo 'this $variable' ==> will output 'this $variable' 
echo "this $variable" ==> will output 'this 1' 
相關問題