PHP:获取数组元素 [英] PHP: get array element

查看:153
本文介绍了PHP:获取数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个code不工作?

Why does this code not work?

echo explode("?", $_SERVER["REQUEST_URI"])[0];

报告说,语法错误,意想不到的'['

奇怪的是,这个作品:

$tmp = explode("?", $_SERVER["REQUEST_URI"]);
echo $tmp[0];

但我真的想避免在这里建立这样一个 $ TMP 变量。

如何解决呢?

有帮助的答案之后,一些剩余的问题:有没有什么好的理由语言的设计使这不可能的?还是因为PHP的实现者只是没有想到这个问题?抑或是出于某种原因难以实现这一目标?

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?

推荐答案

这是当前PHP解析器,你的第一个例子不工作的(愚蠢)的限制。不过,据说PHP的下一个主要版本将解决这个问题。

It's a (silly) limitation of the current PHP parser that your first example doesn't work. However, supposedly the next major version of PHP will fix this.

这篇关于PHP:获取数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆