BlueCatTAT
V2EX  ›  PHP

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

  •  
  •   BlueCatTAT · Nov 9, 2015 · 4548 views
    This topic created in 3845 days ago, the information mentioned may be changed or developed.
    4 replies    2015-11-09 14:58:32 +08:00
    adexbn
        1
    adexbn  
       Nov 9, 2015
    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  
       Nov 9, 2015
    你是要 实现这样?
    ```php
    $a = 1;
    $b = 1;
    $c = '-';
    echo $a.$c.$b;//1-1
    echo eval("return {$a}{$c}{$b};");//0
    ```
    但是 eval 函数在很多情况下会被禁用
    widdy
        3
    widdy  
       Nov 9, 2015
    switch 吧
    Automan
        4
    Automan  
       Nov 9, 2015
    自己动手撸个 parser
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1203 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 23:30 · PVG 07:30 · LAX 16:30 · JFK 19:30
    ♥ Do have faith in what you're doing.