Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想做一个连接来调用我的定义,但 php 不想要。
举例:
define('FOO_1', 'string 1'); define('FOO_2', 'string 2');
我想动态调用它:
$id = 1; echo FOO_.$id;
但它显示:
FOO_1 (不是“字符串 1”);
如何动态调用我的定义?
通过使用constant()
constant()
echo constant('FOO_'.$id);
请参阅此处的文档:http: //php.net/constant
归功于 Yent