可能重复:
是否可以将数组声明为常量
是否可以在PHP中使用数组作为类常量?
即
const MYARRAY = array('123', '234');
Run Code Online (Sandbox Code Playgroud)
如果不是为什么?
xda*_*azz 74
不,你不能.
但是你可以将它声明为静态属性.
public static $MYARRAY = array('123', '234');
Run Code Online (Sandbox Code Playgroud)
---------------更新-----------------------------
数组const可从PHP 5.6获得.
php.net/manual/en/migration56.new-features.php
Alv*_*ong 65
更新:
现在可以在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