The Arry $_GET contains all needed informations. $ _SERVER ['REQUEST_URI'] and parse_url not needed.
As an example I have the following browser line:
http://localhost/php/test.php?par&query=1
Let's see what $ _GET contains
echo '<pre>';
var_export($_GET);
Output
array (
'par' => '',
'query' => '1',
)
With array_keys() I get all keys.
$keys = array_keys($_GET);
var_export($keys);
Output:
array (
0 => 'par',
1 => 'query',
)
The first key I get with (see also comment from @bobble bubble)
echo $keys[0]; //par
or
echo key($_GET);
With array_key_exists () I can check whether a key is available.
if(array_key_exists('query',$_GET)){
echo 'query exists';
}