简体   繁体   English

PHP:使用变量名称回显常量

[英]PHP: echoing a constant with a variable name

How can I do that? 我怎样才能做到这一点?

I have something like: 我有类似的东西:

define($stuff.'_FOO', 'whatever');
echo $stuff.'_FOO';

and it doesn't work :( 它不起作用:(

I just want to echo the constant's value... 我只想回应常数的价值......

Check out constant() . 检查constant()

In your case: 在你的情况下:

echo constant($stuff . '_FOO');

First make a constant: 先做一个常数:

define("FOO_BAR", "something more");

then you can get the value by using constant() : 那么你可以使用constant()来获取值:

echo constant("FOO_BAR");

Read more about constants in the manual . 阅读手册中有关常量的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM