为什么PHP在变量前加$号? [英] Why does PHP have a $ sign in front of variables?

查看:179
本文介绍了为什么PHP在变量前加$号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP和其他一些脚本语言中,语法为$var,而在Java和其他语言中,我们只能使用var.

In PHP and some other scripting languages have the $var syntax while Java and other languages we can do just var.

背后有什么理论吗?这是否有助于他们解析.如果不是,他们为什么会选择在前面加一个额外的角色?

Is there any theory behind it? Does it help them to parse. If not why would they choose to tack on an extra character in front?

推荐答案

它防止变量名与语言关键字冲突,并允许它们以字符串形式插值.

It prevents variable names conflicting with language keywords, and allows them to be interpolated in strings.

这篇关于为什么PHP在变量前加$号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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