سؤال

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?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top