You need another level of indirection. Try:

$constant_value = $$constant_name ;


-----Original Message-----
From: Geoff Caplan [mailto:[EMAIL PROTECTED]]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to