In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Geoff Caplan) wrote:

> 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?

Your error_reporting level must not be all the way up to E_ALL, because 
when I tried your code PHP reported errors that might have helped you solve 
the problem.  Try this:

// We set up the constant
define("CONSTANT_1", "Some value" ) ; //constant name must be in quotes

// Later we try to use it dynamically ...
$constant_number = 1 ;
eval( "echo CONSTANT_$constant_number;" ) ;//tell PHP to treat the name as 
code not as a text string

-- 
CC

-- 
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