eldan88 Posted April 27, 2013 Share Posted April 27, 2013 Hey, I have a question. I am trying to echo out constant using the ternary operator, but its not echoing. Below is one line of code I am using. Any suggestions? echo defined(STORE_ADDRESS) ? STORE_ADDRESS : "" Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/ Share on other sites More sharing options...
Jessica Posted April 27, 2013 Share Posted April 27, 2013 And the problem is? Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426857 Share on other sites More sharing options...
eldan88 Posted April 27, 2013 Author Share Posted April 27, 2013 And the problem is? The constant is not being echoed. Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426861 Share on other sites More sharing options...
Jessica Posted April 27, 2013 Share Posted April 27, 2013 What debugging have you done? It's fairly obvious that either the constant is defined with a blank value, or it's not defined. The code appears fine, and it sounds like its working. Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426862 Share on other sites More sharing options...
eldan88 Posted April 27, 2013 Author Share Posted April 27, 2013 What debugging have you done? It's fairly obvious that either the constant is defined with a blank value, or it's not defined. The code appears fine, and it sounds like its working. Im sorry. I was using the right code for the wrong reason. What I was trying to accomplish is echoing out a constant only if it has been defined using the ternary operator. Is there a way where I can accomplish this? Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426863 Share on other sites More sharing options...
Jessica Posted April 27, 2013 Share Posted April 27, 2013 That is what you're doing. Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426864 Share on other sites More sharing options...
akphidelt2007 Posted April 27, 2013 Share Posted April 27, 2013 You need quotes around STORE_ADDRESS other wise it is using the STORE_ADDRESS constant value to check whether it is defined. So it should be defined('STORE_ADDRESS') Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1426873 Share on other sites More sharing options...
eldan88 Posted April 28, 2013 Author Share Posted April 28, 2013 You need quotes around STORE_ADDRESS other wise it is using the STORE_ADDRESS constant value to check whether it is defined. So it should be defined('STORE_ADDRESS') That worked. Thanks a lot for your help! Link to comment https://forums.phpfreaks.com/topic/277362-echoing-values-with-the-ternary-operator/#findComment-1427008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.