Click to See Complete Forum and Search --> : variable variable
violent j
05-18-2004, 04:21 PM
hello all,
does anybody know how to do something like this??
$method = "GET";
$var = $_$method["var"];
when i do it exactly like this, i get an unexpected T_VARIABLE error
tnx in advance
grtz
solavar
05-18-2004, 04:45 PM
Are you trying to do this...
$method['get'] = "GET"
$var = $$method['get'];
NOTE:
$var = $_$method IS WRONG (parse error, unexpected T_VARIABLE, blah, blah, blah)
$var = $$method IS RIGHT (variable variable)
violent j
05-18-2004, 06:09 PM
nope, won't work either ... i'm using it in this function, maybe it'll get a little more clear
function _GET ($var, $method="_GET") {
if (IsSet ($$method[$var])) {
$retVal = $$method[$var];
} else {
$retVal = "";
}
return $retVal;
} // End function _GET
grtz
ShrineDesigns
05-18-2004, 08:22 PM
you can use $_REQUEST (contains any $_POST, $_COOKIE, and/or $_GET data) instead of trying to figure out which method was used
What's the point in re-inventing the wheel, anyway?
violent j
05-19-2004, 09:36 AM
hmm ... i'll try the $_REQUEST var
well, the point is, instead of putting something like this on top of each page:
if (IsSet ($_GET["action"])) {
$action = $_GET["action"];
} else {
$action = "";
}
i would then to do this:
$action = _GET ("action"); or
$action = _GET("action","POST"); if it was a post-var
grtz
ShrineDesigns
05-19-2004, 10:42 AM
you can shorthand it like this:<?php
foreach($_GET as $key => $value)
{
$$key = $value;
}
?>so, if you have $_GET['action'] after the loop you can get the value like this: $action, instead of $_GET['action']
violent j
05-19-2004, 05:38 PM
yeah, i know, but then maybe i get some variables i don't want, and maybe screw my script.
if i use your code, i could just as well enable register_globals
but tnx for your reply :)
grtz