What you see as "the value of some 'unmentioned' variable" is more generally considered as a query string parameter without a value. So for foo=bar&baz
, foo
has the value bar
and baz
has no value (in PHP its value will be an empty string).
Since the other answers are providing different methods of accessing that parameter name, here are my two cents. You can get the first key of the $_GET
array by using the key
function. If no key is available, key
will return NULL.
Visiting ?somedata=somevalue
var_dump(key($_GET), $_GET);
/*
string(8) "somedata"
array(1) {
["somedata"]=>
string(9) "somevalue"
}
*/
Visiting ?somedata
var_dump(key($_GET), $_GET);
/*
string(8) "somedata"
array(1) {
["somedata"]=>
string(0) ""
}
*/
Visiting ?
var_dump(key($_GET), $_GET);
/*
NULL
array(0) {
}
*/