为什么我不能在 PHP 7 中做常量数组?当我执行此代码时:
define(‘WEEKDAYS’, [ ‘Mon’, ‘Tue’ , ‘Wed’ , ‘Thu’ , ‘Fri’ ] );
var_dump(WEEKDAYS);
echo PHP_VERSION;
Run Code Online (Sandbox Code Playgroud)
我得到:
字符串(8)“工作日”
7.0.0
您没有使用正确的语法:
//Simple array
define("CONSTANT_ARRAY", ['one', 'two', 'three',]);
//Multidimensional array
define("CONSTANT_ARRAY_MULTIDIMENSIONAL", [
'fruits' => ['pear', 'apple', 'pineapple',],
'cars' => ['mustang', 'chevette', 'ferrari',],
'games' => ['streetfighter', 'lol', 'dota',],
]);
//Inside class you must use const keyword
const MYCONSTANT = ['pear', 'apple', 'pineapple',];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2187 次 |
| 最近记录: |