没有变量名的$ _GET [关闭]

Many times I tried to write different types of codes in different languages. When I tried to write something like this:

if (!isset($_GET[""])) $_GET[""] = false;

The compiler does not report an error. OK, we have this construction without variable name. Is here one way to use this construction in practice? I think it's nonsense.

I think that only $_GET is usable in practice, like:

if (count($_GET) > 0) do something

empty($_GET) and count($_GET) are working here for me!

I can't understand what you want to achieve by this code:

if (!isset($_GET[""])) $_GET[""] = false;

It's possible for php to assign empty string as array key and it will be accessible like:

$array[0]['']

For your checking you can use such function for example:

function GET($key, $default = null) {
    return isset($_GET[$key]) ? $_GET[$key] : $default;
}

If you're talking about the usability of $_GET[""] - you can't set it using URL.

If you go to the URL test.php?=3 you will get an empty $_GET

If you go to the URL test.php?""=3 you will be able to access it using $_GET["\"\""]

So there is no way to set a variable in the URL and retrieve it with $_GET[""];

You can set the key to an empty string from the code however:

$_GET[""] = 3;
echo $_GET['']; // 3
echo $_GET[""]; // 3

if you test the following code with a url like 'http://domain.com':

print_r($_GET);
echo '<br>';
if(isset($_GET))
{
   echo '$_GET IS SET<br>';
}

if(!empty($_GET))
{
   echo '$_GET IS NOT EMPTY<br>';
}

if(count($_GET) > 0)
{
   echo '$_GET IS NOT EMPTY<br>';
}

you 'll get

Array ( ) 
$_GET IS SET

According to that then is up to you what you want to check or do keep in mind that $_GET is always set even if you do http://www.domain.com or this http://www.domain.com/index.php?test=adsf

What you did with $_GET[''] = 'smthing' is like having an array arr['test'] = 'smthing'; altho you didn't gave a key of test instead an empty one, which you can't handle properly when it comes to $_GET.

so you should check for smthing specific if you ask me.

if(isset($_GET['test']) && $_GET['test'] == 'adsf')
{
   doSomething();
}

This is just a simple example further validation should occur.