I tried to do var_dump($_SERVER[]);
I received this error:
Cannot use [] for reading
Any hints for me?
I tried to do var_dump($_SERVER[]);
I received this error:
Cannot use [] for reading
Any hints for me?
Currently, every answer fails to answer the Why?
.
$_SERVER[]
is the syntax used to create a new sequential element. The new key will be numertical, starting from 0.
Example:
<?PHP
$array = [];
$array[] = 1;
$array['a test'] = 'nope';
$array[] = 1;
print_r($array);
This will give the following output:
Array ( [0] => 1 [a test] => nope [1] => 1 )
Why can't you use it for reading?
This is easy: PHP expects you to pass a value to add to the array. Since you don't give any, PHP can't read the element that is trying to create. That is like hatching an egg before there was ever a chicken.