Neo's Blog

首頁 相本 討論 書籤

分類目錄
本站日誌 (51)
碎碎唸啦 (173)
網站架設 (84)
程式設計 (161)
軟體使用 (69)
電子商務 (126)
經營奇想 (48)
基金理財 (11)
聰明消費 (87)
電影心得 (47)
開放原碼 (16)
工作記錄 (2)
毛毛小記 (9)
就是不同 (2)




歷史資料
 




August 12, 2006
[PHP] 單引號跟雙引號的不同

為什麼很多人都說用單引號會讓 PHP 執行速度比較快?

原因在於 PHP 會解譯「雙引號」字串內的變數,而「單引號」則視為純字串出,PHP 不會再處理單引號內的內容。

如果還是聽不懂在講什麼,可以參考範例:

$var = $value; // ok
$var = "$value"; // ok, but double quotes are not necessary
$var = '$value'; // will not work (single quotes will not allow parsing)

('.' the period adds/connects variables, functions, etc. together.
Oftentimes programmers will leave spaces around the ' . ' to make
things easier to read.)

$var = 'This is the ' . $value . ' of things.'; // ok - preferred
technique
$var = "This is the $value of things."; // ok, but harder to read/debug
$var = 'This is the $value of things.'; // will not parse $value
$var = This is the $value of things.; // error

$var = $array['name']; // ok, generally the preferred technique
$var = $array["name"]; // ok, but why use double quotes if they are not
necessary?
$var = "$array[name]"; // ok, but harder to read/debug - poor coding
style

$var = 'Name: ' . $array['name']; // ok - preferred technique
$var = "Name: $array[name]"; // ok, but harder to read/debug - poor
coding style
$var = "Name: $array["name"]"; // error
$var = "Name: $array['name']"; // error

exampleFunction($value); // ok
exampleFunction("$value"); // ok, but double quotes are not necessary
exampleFunction('$value'); // will not parse $value

以上節錄自
10 Tips That Every PHP Developer Should Know, Part 2

 
由 Neo 發表於 August 12, 2006 10:44 AM 收進你的MyShare個人書籤  

嗯,簡單明瞭
小弟最近在學PHP
站長網站裡有好多資料
都好有幫助

以後還請多多指教


ERIC 發表於 August 15, 2006 01:59 AM
發表迴響  
(*星號開頭為必填欄位)











(請輸入您看到的數字,看不到請按右鍵->顯示圖片)


記住我的資訊?







Copyright 2005 Neo's Blog All rights reserved.