論陣列PHP文檔頁面,給出的例子碼如下:PHP 5.4中可用的數組聲明語法的變體是什麼?
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// as of PHP 5.4
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
是否意味着所述第一代碼是無效的在PHP 5.4,或爲所述第二代碼只是一個替代?
論陣列PHP文檔頁面,給出的例子碼如下:PHP 5.4中可用的數組聲明語法的變體是什麼?
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// as of PHP 5.4
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
是否意味着所述第一代碼是無效的在PHP 5.4,或爲所述第二代碼只是一個替代?
第一個代碼仍然有效。第二個符號只是一個更短,更方便的選擇。
正如其他人指出的第一個是有效的。第二個是較短的版本。
這裏是第二個版本的優點和缺點:
Pro Good for framework development when dealing with long parameterlists Other web languages have similar syntax Readable Contra Yet another alias Would take distinctness from [] Not searchable through search engines Unreadable Patch may be difficult to maintain in future
我想抨擊誰說第二個版本在頭部「不可讀」。 – NullUserException
速記符號開始提供5.4但雙方仍然有效。 – NullUserException
http://php.net/manual/en/migration54.new-features.php和http://php.net/manual/en/migration54.deprecated.php應該回答你的問題。就像在5.4環境中運行代碼一樣。 –