[SOLVED] external constants with dynamic name?
Posted: Thu Mar 03, 2005 7:14 am
Hello
I have 1 php file called defines.php with the following definition:
a second php file called defines.php (different folder) with the following definition:
In my code include the correct file using:
Now I have access to either Age_Dog or Age_Cat depending on what file was included.
I have a variable called $animal which indicates which constant is available. The value of the $animal variable is either 'Dog' or 'Cat'
I would like to define one variable called $animalAge which will hold the correct age depending on what file was included
I tried doing:
When I then try to refer to the $animalAge variable, I get an error that variable $animalAge isn't defined
does anyone know how I can do this?
I am looking for a solution using eval (not if else and other conditionals)
regards
I have 1 php file called defines.php with the following definition:
Code: Select all
define("Age_Dog", 7);Code: Select all
define("Age_Cat", 3);Code: Select all
require_once(<path to file>/defines.php);I have a variable called $animal which indicates which constant is available. The value of the $animal variable is either 'Dog' or 'Cat'
I would like to define one variable called $animalAge which will hold the correct age depending on what file was included
I tried doing:
Code: Select all
eval('\$animalAge = "Age_"' . $animal );does anyone know how I can do this?
I am looking for a solution using eval (not if else and other conditionals)
regards