本文介绍了是否可以将数组声明为常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以定义一个常量,例如
We can define a constant like
define("aconstant','avalue');
我们不能像下面这样定义数组吗?
Can't we define array in this fashion like below ?
define("months",array("January", "February", ---);
推荐答案
更新:在PHP 7(参考)
// Works as of PHP 7
define('ANIMALS', array(
'dog',
'cat',
'bird'
));
echo ANIMALS[1]; // outputs "cat"
原始答案
从php.net ...
From php.net...
$months = array("January,"February",...)
就可以了.
这篇关于是否可以将数组声明为常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!