Why does this code not work?
echo explode("?", $_SERVER["REQUEST_URI"])[0];
It says syntax error, unexpected '['
.
Oddly, this works:
$tmp = explode("?", $_SERVER["REQUEST_URI"]);
echo $tmp[0];
But I really want to avoid to create such a $tmp
variable here.
How do I fix it?
After the helpful answers, some remaining questions: Is there any good reason of the design of the language to make this not possible? Or did the PHP implementors just not thought about this? Or was it for some reason difficult to make this possible?