最先想到的方法是这样:
define('SIGN_CODE', array('9df512','59gf1g','5eg7h1','g1agf5','f5e151','g51gfr','a5481s'));
运行报错:Warning: Constants may only evaluate to scalar values in
原因是:define常量的值;仅允许标量和 null。标量的类型是 integer, float,string 或者 boolean。所以数组是不允许的
通常做法是采用下面的方法去间接地去定义“数组常量”
方法一:采用eval()函数
<?php
define('SIGN_CODE', "return array('9df512','59gf1g','5eg7h1','g1agf5','f5e151','g51gfr','a5481s');");
$SIGN_CODE=eval(SIGN_CODE);
var_dump($SIGN_CODE);
方法二:采用json_encode()函数
<?php
define('SIGN_CODE', "return array('9df512','59gf1g','5eg7h1','g1agf5','f5e151','g51gfr','a5481s');");
$SIGN_CODE=json_decode(SIGN_CODE,true);
var_dump($SIGN_CODE);
方法三:采用serialize()函数
<?php
define('SIGN_CODE', "return array('9df512','59gf1g','5eg7h1','g1agf5','f5e151','g51gfr','a5481s');");
$SIGN_CODE=unserialize(SIGN_CODE);
var_dump($SIGN_CODE);