|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Is it possible to have an include file with nothing but $variables?
Thanks in advance to the DevArticle community - you guys are the greatest!
Today's question - Let's say I have a table with fields that hold one or two digit number values that correspond to arrays like the one below: $eyewearkey = array("Perfect Vision","Fasionable Glasses","Glasses to Read","Contact Lenses","Cheap Sunglasses","Rather Not Say","Glasses"); Throughout the site, there are many places where these variables are needed and I was wondering if they could reside within an include file? - Mojoman
__________________
$mybrain = "mush"; ------------------------------------------- http://www.loftsboston.com http://www.gregdawsondesign.com |
|
#2
|
|||
|
|||
|
Most certainly!
Make a "config.php" file and put all of your global definitions in there... It's where things like $db_user, $db_pass, etc... should also be kept. |
|
#3
|
|||
|
|||
|
If you will be using these var's throughout functions, the norm is to create constants of them - your code in return will be alot cleaner:
PHP Code:
Now, you can use the constant throughout your script, in functions or where ever by this -> PHP Code:
The above would echo what ever is bound to the constant...
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#4
|
|||
|
|||
|
Couple of things about Constants. One is that they can only be scalars. Objects and arrays are not permitted.
Also, you can't use them in Here-docs (for obvious reasons). Other than that they are definitely the way to go. |
|
#5
|
|||
|
|||
|
Quote:
Yeah, I actually find it annoying that constants aren't prefixed by $ like variables... To me it somehow seems like it breaks format. (And as you pointed out, they are far more restrictive than plain variables.) If you end up using variables instead of defining constants, just be careful with your assignment operators so you don't change something you didn't mean to: PHP Code:
|
|
#6
|
|||
|
|||
|
...and don't forget the ol'
PHP Code:
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Is it possible to have an include file with nothing but $variables? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|