igorek wrote:trow me an example just for fun.
As dagon said, look at the manual for [man]extract/man. Although it doesn't create constants (only variables), I think extract() would be better than your foreach() loop since it allows prefixing (to avoid variable name collisions).
I also don't know why you'd ever want to extract the elements of the $SESSION array into constants. If the data is truly constant, why not put it in a config file? And if it's not, why not just keep it in the $SESSION array where it (apparently) belongs, since the array itself is already a superglobal?
igorek wrote:The way I figure is to build my/your/else table in db, hopefully you will not name your column names in table as digits/numeric
You said nothing about a database in your first post (actually, you didn't say anything at all in your first post - you just posted a snippet of code with no explanation 🙂), so how were we to assume you would only use the above code when session data comes from a database?
EDIT:
igorek wrote:What I mean is ... extract(); function is a great suggetion but how would you use it in my situation.
I'd change this:
// $_SESSION Super Global variables
if (isset($_SESSION)) {
// run em as their own Constant variables
foreach($_SESSION as $key => $value) {
define("$key","$value",true);
// or if preferred as variables
// $$key = $value;
}
}
to this:
extract($_SESSION);
or, even better,
extract($_SESSION, EXTR_PREFIX_ALL, 'cfg_');
where 'cfg' assumes this is some sort of configuration data (just as an example) and may be substituted with some other short prefix that fits the description of the variables you're creating.