V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
BlueCatTAT
V2EX  ›  PHP

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

  •  
  •   BlueCatTAT · 2015-11-09 11:02:58 +08:00 · 3681 次点击
    这是一个创建于 3303 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    2015-11-09 14:58:32 +08:00
    adexbn
        1
    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
        2
    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
        3
    widdy  
       2015-11-09 14:58:17 +08:00
    switch 吧
    Automan
        4
    Automan  
       2015-11-09 14:58:32 +08:00
    自己动手撸个 parser
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   922 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:57 · PVG 03:57 · LAX 11:57 · JFK 14:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.