php 运算符当作变量要怎么做

2015-11-09 11:02:58 +08:00
 BlueCatTAT
3493 次点击
所在节点    PHP
4 条回复
adexbn
2015-11-09 11:37:01 +08:00
Basics ¶

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

Note: For our purposes here, a letter is a-z, A-Z, and the bytes from 127 through 255 (0x7f-0xff).
Note: $this is a special variable that can't be assigned.
mrgeneral
2015-11-09 14:42:39 +08:00
你是要 实现这样?
```php
$a = 1;
$b = 1;
$c = '-';
echo $a.$c.$b;//1-1
echo eval("return {$a}{$c}{$b};");//0
```
但是 eval 函数在很多情况下会被禁用
widdy
2015-11-09 14:58:17 +08:00
switch 吧
Automan
2015-11-09 14:58:32 +08:00
自己动手撸个 parser

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/234727

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX