سؤال
Using the GET protocol with php I can get data passed to my program. With something like $_GET["fname"];
.
What I'm wondering is there any way to make some sort of a catch all. Where I did not need to know the var name before runtime?
المحلول
It's just an associative array, handle it like any other:
foreach ($_GET as $name => $value) {
echo "$name: $value\n";
}
If you just want "the first" value or "the one" value, do:
$value = current($_GET);
نصائح أخرى
You can also pull items out of $_GET
like this:
$var = 'fname';
$fname = $_GET[$var];
You can pull multiple items like this:
foreach(array('fname', 'lname') as $var) {
echo $var.' = '.$_GET[$var].'<br>;
}
Is this what you meant?
لا تنتمي إلى StackOverflow