我正在尝试动态创建一个常量名称,然后获取该值。
define( CONSTANT_1 , "Some value" ) ;
// try to use it dynamically ...
$constant_number = 1 ;
$constant_name = ("CONSTANT_" . $constant_number) ;
// try to assign the constant value to a variable...
$constant_value = $constant_name;
但我发现 $constant 值仍然包含常量的名称,而不是值。
我也尝试了第二级间接$$constant_name
但这将使其成为变量而不是常量。
有人可以解释一下吗?
http://dk.php.net/manual/en/function.constant.php
echo constant($constant_name);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)