I am trying to figure out the best course of action to handle holding lagnuage values.
For example:
language_english.php would have
define('_FOO','foo');
or
$lang['foo'] = 'foo';
$GLOBALS['lang_english'] = $lang['foo'];
Anyone have any thoughts, or even a better suggestion? Some on told me that defines are slower than arrays, but arrays use more memory.
Defines or arrays?
Moderator: General Moderators
- Technocrat
- Forum Contributor
- Posts: 127
- Joined: Thu Oct 20, 2005 7:01 pm
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
In programming very little is black and white. If you try to make black and white decisions you will end up making the wrong ones far too often. In this case you need to judge whether to use constants (defines) over arrays on a case by case basis. Also these two things are fundamentally different; make sure you understand what they both imply.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Technocrat
- Forum Contributor
- Posts: 127
- Joined: Thu Oct 20, 2005 7:01 pm
I sometimes store my data in a data object like so:
Saves a few key strokes [''].
And you can still loop through it with foreach.
And in a pinch if you need to access it as an array you just...
And it magically becomes an array. And when your done switch it back to an object.
Code: Select all
$data->foo = bar;And you can still loop through it with foreach.
And in a pinch if you need to access it as an array you just...
Code: Select all
$data = (array) $data;Code: Select all
$data = (object) $data;