Re: note 9772 added to define

From: Date: Thu, 23 Nov 2000 00:10:46 +0000
Subject: Re: note 9772 added to define
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-8011@lists.php.net to get a copy of this message
paul@cnt.org writes: > Can constants, after being defined, be refer to by something other > than their literally defined name? In other words, can a variably > refer to a constant's value? > > Ex: > define("SOME_CONSTANT", 1); > $somevar = "CONSTANT"; > echo SOME_$somevar; ????? > > http://www.php.net/manual/function.define.php This note will be deleted. However, you might want to look into eval() to do something like that. Otherwise, you may as well just use variables. <?php error_reporting(E_ALL); define('SOME_CONSTANT', 'foo' ); $somevar = 'CONSTANT'; eval("echo SOME_$somevar;"); ?> Hope this helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.notes (#8011) next »