Alex Alex -5 years ago 115
PHP Question

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

Answer Source

Check out constant().

In your case:

echo constant($stuff . '_FOO');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download