SV: [PHP] Variable name for constants?

From: Date: Thu, 11 Dec 2008 08:48:24 +0000
Subject: SV: [PHP] Variable name for constants?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-284470@lists.php.net to get a copy of this message
> > I dont think you can do that with a constant, but you can do this a > > normal variable: > > > > I stand under correction form my previous email, it can be done: > > define('TEST', 'the value of constant TEST'); > > $var= 'TEST'; > > echo constant($var); This may be too early in the morning for me, but I don't get it.. ;-) Say I have these definitions; define("IMG_HOME", "pic1.png"); define("IMG_AWAY", "pic2.png"); define("IMG_ELSE", "pic3.png"); Then a function should present the right image based on a variable (pseudocode): function show($name) { present_img( IMG_$name ); } If I understand right (probably not...), then I could concat and do like this? present_img( constant("IMG_" . $name) );

« previous php.general (#284470) next »