php 7.0.0 中定义的常量数组转换为字符串

Ale*_*lin 1 php php-7

为什么我不能在 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

cap*_*pcj 5

您没有使用正确的语法:

//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)