简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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