Jump to content

define varibale


Destramic

Recommended Posts

The brackets {} are only used within a double quoted string (or hredoc method) to have a variable interpreted. One of the following methods would work (I'd go with the first)

echo $var._VAR;

echo "{$var}"._VAR;

 

EDIT: Scratch that. I misread what you were trying to do. You are defining a constant and then trying to access that constant dynamically. I don't know of a way to do that. You could instead define the TEST_VAR as an array

$config = array();
$config['TEST_VAR'] = 'hello';
$var = "TEST";
echo $config["{$var}_VAR"];

Link to comment
Share on other sites

OK, a quick search shows a solution using constants

define ('TEST_VAR', 'hello');
$var = "TEST";
echo constant("{$var}_VAR");
//Output: hello

 

thanks for that. good to know. i was stumped.

 

Yeah I had no idea either. But, it was right there in the manual for constants! Who would have thought to look there?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.