請看下面的代碼如果變量被雙引號括起來,爲什麼會有錯誤信息?
<?php
//The array is storing a blog entry in it
$entry = array ('title' => 'sample title',
'date' => 'August 9, 2011',
'author' => 'daNullSet',
'body' => 'I shall become a web developer IA',);
echo "The title of the blog is ".$entry['title']."<br />";
?>
上面的代碼執行得很好,但是當我用雙引號括$入門[「標題」],而在echo語句和其它字符串連接返回以下分析錯誤。
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\php-ex\test.php on line 7
你能指導一下錯誤的原因嗎?我對編程絕對陌生。謝謝
請刪除'「」'後**‘我要成爲一名Web開發IA’** – Jalpesh 2012-08-09 09:17:06
回聲「博客的標題是「」。$入門[‘標題’]。'「
'; – 2012-08-09 09:17:39
@Jalpesh額外的逗號是可選的,我將_always_包含在PHP中。所以這是一個品味問題。 OP:不要只包括那些運行良好的coede,包括實際拋出錯誤的代碼 – Evert 2012-08-09 09:21:42