PHP 常量數組

PHP 7 新特性 PHP 7 新特性

在 PHP 5.6 中僅能通過 const 定義常量數組,PHP 7 可以通過 define() 來定義。

實例

<?php
// 使用 define 函數來定義數組

define('sites', [
   'Google',
   'zaixian',
   'Taobao'
]);

print(sites[1]);
?>

以上程式執行輸出結果為:

zaixian

PHP 7 新特性 PHP 7 新特性