可能的重复项:
是否可以将数组声明为常量
是否可以在 PHP 中使用数组作为类常量?
即
const MYARRAY = array('123', '234');
如果不是为什么?
不,你不能。
但是您可以将其声明为静态属性。
public static $MYARRAY = array('123', '234');
---------------更新-----------------------------
数组常量可从 PHP 5.6 开始获得。
php.net/manual/en/migration56.new-features.php
更新:
这在 PHP 5.6 https://php.net/manual/en/migration56.new-features.php 中可用
不,您不能将数组分配给 PHP 常量。
在 http://www.php.net/manual/en/language.constants.syntax.php
常量只能计算为标量值
这就是原因。
示例的标量值为 int
、 float
、 string