Chris92 Posted September 24, 2010 Share Posted September 24, 2010 I was wondering if there is a way to get a constant by using a variable connected to it, eg: define( 'CONSTANT_LOL', 'haha' ); $var = 'LOL'; echo CONSTANT_$var; Any help is appreciated, Chris Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2010 Share Posted September 24, 2010 constant Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115051 Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Author Share Posted September 24, 2010 So I'll have to put them into objects? Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115054 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2010 Share Posted September 24, 2010 No, that's only an example. mixed constant ( string $name ) Just supply the parameter with the string value you want to get the constant value of - echo constant("CONSTANT_$var"); Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115058 Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Author Share Posted September 24, 2010 Okay, thanks very much! Works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115063 Share on other sites More sharing options...
rwwd Posted September 24, 2010 Share Posted September 24, 2010 Doesn't that deviate from the definition of constant? Change it's value by al means, create a switch/on/off gismo that's alright, but dynamically altering it's name, I would love to see the context of it application. Rw Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115070 Share on other sites More sharing options...
KevinM1 Posted September 24, 2010 Share Posted September 24, 2010 Doesn't that deviate from the definition of constant? Change it's value by al means, create a switch/on/off gismo that's alright, but dynamically altering it's name, I would love to see the context of it application. Rw It seems like he has a series of constants defined and wants to dynamically choose which one to use based on an external variable. Quote Link to comment https://forums.phpfreaks.com/topic/214284-variable-constant-help/#findComment-1115075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.