What does $$ in php mean?

This question already has an answer here:

  • What does $$ (dollar dollar or double dollar) mean in PHP? 6 answers

  • In PHP, $$ means you are about to inflict years of pain and suffering on at least one maintenance programmer. Note that you might wind up being that maintenance programmer.

    It is a variable variable. Imagine this:

    $quux = 'bar';
    $foo[$quux] = "baz";
    echo $foo['bar']; //prints baz
    

    if there was no such thing as arrays, you might try something like this:

    $quux = 'bar';
    $$quux = "baz";
    echo $bar; //prints baz
    

    luckily we do have arrays so please don't use variable variables unless you are doing something convoluted and magical * and have no other choice.

    * : Please don't do convoluted magical things, either.


    这些被称为变量变量。

    $foo = 'bar';
    $id = 'foo';
    
    echo $id;  // prints foo
    echo $$id; // prints bar
    

    in the PHP manual of course

    http://www.php.net/manual/en/language.variables.variable.php

    note that it's obsolete and senseless syntax and you should always use arrays instead.

    链接地址: http://www.djcxy.com/p/59092.html

    上一篇: 为什么在变量的前面有两个$$符号?

    下一篇: $$在php中是什么意思?