开发者

PHP: echoing a constant with a variable name

开发者 https://www.devze.com 2023-02-24 03:39 出处:网络
How can I do that? I have something like: define($stuff.\'_FOO\', \'whatever\'); echo $stuff.\'_FOO\'; and it doesn\'t work :开发者_开发百科(

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().

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():

echo constant("FOO_BAR");

Read more about constants in the manual.

0

精彩评论

暂无评论...
验证码 换一张
取 消