Jump to content

defining a variable


shuka79

Recommended Posts

Hi guys,

I have a php page that define a load of varibles in the format

 

define('EX_1', 'example 1');
define('EX_2', 'something else');

 

this goes up to EX_10, when the page is displayed it list all the different links, and when one is click it will add ?show=1 to the url, so when the page loads it will show all the details for EX_1

The issue I am having is that it is not getting the details I have the following code

 

echo EX_$_REQUEST['show'];

 

but this just returns EX_1.

If I put it in hard code

 

echo EX_1;

It will display example 1 on the page.

 

Can any one see what I am missing?

 

Thanks in advance for your help

Cheers

Shuka

 

 

Link to comment
https://forums.phpfreaks.com/topic/206094-defining-a-variable/
Share on other sites

echo constant(EX_ . $_REQUEST['show']);

 

The constant function is what you are going to need to use. You may also want to check if the variable is_defined before accessing it, given that show could be any number (either that or default show to something if it is not set / out of the range of valid values).

Link to comment
https://forums.phpfreaks.com/topic/206094-defining-a-variable/#findComment-1078356
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.