在$ _POST变量中使用引号,撇号或不使用引号和撇号有什么区别? [英] What is the difference in using quotes, apostrophes or neither in $_POST variables?

查看:139
本文介绍了在$ _POST变量中使用引号,撇号或不使用引号和撇号有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发布了一个问题,其中的代码无效,并建议我在$ _POST变量中添加撇号.

I recently posted a question in which the code did not work, and was suggested i add apostrophes to my $_POST variables.

$_POST[variable]

推荐人(?)

$_POST['variable']

PHP.net推荐

$_POST["variable"]

您使用什么,为什么?
使用其他之一会产生什么区别?

What do you use, and why?
What differences arise when using one of the others?

推荐答案

使用"'之间没有实质性区别.数组键可以是整数或字符串.字符串用PHP引用.在这种情况下,不使用引号是可行的,但是PHP首先会检查键是否为常量,然后再将其解释为字符串.不引用数组键是 PHP文档中不推荐的.

There is no substantial difference between using " and '. Array keys can be either integers or strings. Strings are quoted in PHP. Not using quotes in this case works, but PHP checks if the key is a constant first, then falling back on interpreting it as a string. Not quoting array keys is discouraged in the PHP documentation.

这篇关于在$ _POST变量中使用引号,撇号或不使用引号和撇号有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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