RE: [PHP] Dynamic constant names
| From: | Neil Kimber | Date: | Tue, 27 Mar 2001 13:43:02 +0000 |
| Subject: | RE: [PHP] Dynamic constant names | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-45723@lists.php.net to get a copy of this message | ||
You need another level of indirection. Try:
$constant_value = $$constant_name ;
-----Original Message-----
From: Geoff Caplan [mailto:geoff@productivity.co.uk]
Sent: 27 March 2001 14:19
To: PHP General List
Subject: [PHP] Dynamic constant names
Hi folks
I am trying to create a constant name dynamically and then get at the
value.
// We set up the constant
define( CONSTANT_1 , "Some value" ) ;
// Later we try to use it dynamically ...
$constant_number = 1 ;
$constant_name = ( "CONSTANT_" . $constant_number ) ;
// We try to assign the constant value to a variable...
$constant_value = $constant_name ;
But we find that $constant value still contains the NAME of the
constant, and not the VALUE.
Am I misunderstanding something? Is there any way that this can be done?
Thanks
Geoff Caplan
Caplan Associates
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net