我正在尝试动态创建一个常量名称,然后获取该值。
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
但这会使它成为一个变量而不是一个常数。
有人可以对此有所了解吗?