-1

please can you help me in this problem?
If in PHP I have a defined constant, can I use that constant name within a variable name? For example how can I do something like the following in valid php syntax?

define ("HELLO", "hello-you");
$var_HELLO = "something";
echo $var_HELLO;

where HELLO in the variable name is the defined constant.

many thanks.

JB-Franco
  • 256
  • 1
  • 3
  • 17
  • That's a maintenance nightmare waiting to happen. Why would you need to define a variable name using a constant? – Quentin May 05 '14 at 11:24
  • i don't see the use of this but oh well – kennypu May 05 '14 at 11:27
  • 3
    Don't. Please, just don't! – vascowhite May 05 '14 at 11:28
  • I use variables for many scopes as html nav, url links, etc... and I add every time same prefixes in a very great number of these variables. Maybe this can reduce the "maintenance nightmare"... @Quentin. And however it is also my curiosity that wants to know it :) – JB-Franco May 05 '14 at 11:33
  • 1
    Use associative arrays if you want to group a bunch of variables together. – Quentin May 05 '14 at 11:34

1 Answers1

5

If you absolutely have to do this,

define ("HELLO", "hello-you");
$var_{HELLO} = "something";
echo $var_{HELLO};
Mark Baker
  • 209,507
  • 32
  • 346
  • 385