我想做一个连接来调用我的定义,但php不想要。
通过示例:
define('FOO_1', 'string 1');
define('FOO_2', 'string 2');
我想动态调用它:
$id = 1;
echo FOO_.$id;
但它显示:
FOO_1 (不是"字符串 1");
如何动态调用我的定义?
通过使用constant()
echo constant('FOO_'.$id);
在此处查看文档:http://php.net/constant
致谢延特
我想做一个连接来调用我的定义,但php不想要。
通过示例:
define('FOO_1', 'string 1');
define('FOO_2', 'string 2');
我想动态调用它:
$id = 1;
echo FOO_.$id;
但它显示:
FOO_1 (不是"字符串 1");
如何动态调用我的定义?
通过使用constant()
echo constant('FOO_'.$id);
在此处查看文档:http://php.net/constant
致谢延特