天天看点

PHP学习笔记—— PHP可变变量;

<?php

    $hello = "world";

    $$hello = "你好";

    echo $world; // 输出的值是“你好”
           
<?php

    $hello = "world";

    $$hello = "name";

    $$$hello = "age";

    $$$$hello = "sex";

    echo $hello; // world
    echo"<br>";
    echo $$hello; // name
    echo"<br>";
    echo $$$hello; // age
    echo"<br>";
    echo $$$$hello; // sex
    echo"<br>";
    echo $world; // name
    echo"<br>";
    echo $age; // sex
           
变量的值前面加了$符,这个值就作为另一个变量名,可以有多层这种可变变量!
           
<?php


    $hello = "world";

    $abc$hello = "name"; // $abcworld 是不对的!

    $$hello = "name";

    $$$hello = "age";

    $$$$hello = "sex";

    echo $hello; // world
    echo"<br>";
    echo $$hello; // name
    echo"<br>";
    echo $$$hello; // age
    echo"<br>";
    echo $$$$hello; // sex
    echo"<br>";
    echo $world; // name
    echo"<br>";
    echo $age; // sex
           
PHP学习笔记—— PHP可变变量;
PHP学习笔记—— PHP可变变量;