1

我想做一个连接来调用我的定义,但 php 不想要。

举例:

define('FOO_1', 'string 1');
define('FOO_2', 'string 2');

我想动态调用它:

$id = 1;
echo FOO_.$id;

但它显示:

FOO_1
(不是“字符串 1”);

如何动态调用我的定义?

4

1 回答 1

6

通过使用constant()

echo constant('FOO_'.$id);

请参阅此处的文档:http: //php.net/constant

归功于 Yent

于 2012-08-14T14:15:37.000 回答