简体   繁体   中英

PHP - Define a constant and use it in a variable name

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.

If you absolutely have to do this,

define ("HELLO", "hello-you");
$var_{HELLO} = "something";
echo $var_{HELLO};

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