可能重复:
Is it possible to declare an array as constant
是否可以将数组用作PHP中的类常量
I.e
const MYARRAY = array('123', '234');如果不是,为什么?
发布于 2012-06-25 14:49:31
更新:
这在PHP5.6 https://php.net/manual/en/migration56.new-features.php中现已可用
不,你不能将数组赋给PHP常量。
在http://www.php.net/manual/en/language.constants.syntax.php中
常量只能计算为标量值
这就是原因。
例如,标量值有int、float、string
发布于 2012-06-25 14:40:05
不,你不能。
但您可以将其声明为静态属性。
public static $MYARRAY = array('123', '234');PHP5.6提供了数组常量。
https://stackoverflow.com/questions/11184469
复制相似问题