不要PHP数组键需要我们包裹在报价? [英] Do PHP array keys need to we wrapped in quotes?

查看:106
本文介绍了不要PHP数组键需要我们包裹在报价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面哪一个是正确的?首先code有$​​ _GET数组中没有报价,第二个呢,我知道你都应该让他们当它是文本字符串,但在这种情况下,它是一个变量,还什么样,如果关键是多少?

暂无报价

 函数arg_p($名称,$默认= NULL){
  返回(使用isset($ _ GET [$名))? $ _GET [$名称]:$默认值;
}

与报价

 函数arg_p($名称,$默认= NULL){
  收益率(使用isset($ _ GET ['$名称']))? $ _GET ['$名称']:$默认值;
}


解决方案

第一个将使用 $名称的值作为重点,而第二个将使用文字字符串'$名称'的关键。

Which one below is correct? First code has no quotes in the $_GET array and the second one does, I know you are supposed to have them when it is a string of text but in this case it is a variable, also what about if the key is a number?

no quotes

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

with quotes

function arg_p($name, $default = null) {
  return (isset($_GET['$name'])) ? $_GET['$name'] : $default;
}

解决方案

The first one will use the value of $name as key while the second will use the literal string '$name' as key.

这篇关于不要PHP数组键需要我们包裹在报价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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