Variable variable using constant
| From: | Marc Guay | Date: | Wed, 12 Oct 2011 18:51:14 +0000 |
| Subject: | Variable variable using constant | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-315252@lists.php.net to get a copy of this message | ||
Hi folks,
Let's say that I have 2 constants
DEFINE('DESKTOP_URL_en', "http://www.website.com/index.php?page=home");
DEFINE('DESKTOP_URL_fr', "http://www.website.com/index.php?page=accueil");
and I would like to populate the value of an href with them depending
on the user's language. $_SESSION['lang'] is either 'en' or
'fr'.
How would I go about referring to this variable?
I have tried:
${'DESKTOP_URL_'.$_SESSION['lang']};
${DESKTOP_URL'.'_'.$_SESSION['lang']};
{DESKTOP_URL'.'_'.$_SESSION['lang']};
etc, to no avail.
If it is a regular variable I'm fine, it's the CONSTANT_FORMAT that
seems to be causing my brain some issues.
Thanks,
Marc